Cant get react native project to run on android - android

I've been at this for a whole day.
I created a new project using npx react-native init Project. But If I try to run it on android I get this:
FAILURE: Build failed with an exception.
* What went wrong:
Incompatible magic value 0 in class file java/util/logging/ErrorManager
I've went through the docs many times. When I run npx react-native doctor, I get this:
Android
✓ JDK
✖ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.3
✓ ANDROID_HOME

So there were a few things that were causing this issue.
✖ Android Studio - Required for building and installing your app on Android
It seems that npx react-native doctor looks for /opt/android-studio, after placing my android studio in /opt/, it was able to detect it.
✖ Android SDK - Required for building and installing your app on
Android
Versions found: N/A
Version supported: 29.0.3
From what I understood, react native uses sdkmanager script to look for sdk which comes with command line tools when you install android studio. In my case, when I ran the script it was giving me errors. The reason for that was that I hadn't created JAVA_HOME environment variable. So, after creating the environment variable and adding it to PATH, the sdkmanager script ran successfully and so did the react native project.
TL;DR
You need to have your android studio folder in opt and it must be named android-studio.
Install android sdk command line tools(latest) and add it to your PATH like this export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
Also create JAVA_HOME and add it to PATH.

It's look you don't have installed Android Studio in your system.
Try to install from official site https://developer.android.com/studio#downloads
Or use snap https://snapcraft.io/install/android-studio/manjaro
sudo snap install android-studio --classic

Related

Build Android app in command-line with Android Studio on Mac

I installed Android Studio on my Mac. I have an android project. I'd like to build it in command-line. If I try to build, or even just get the available tasks:
./gradlew tasks
I got this error:
No Java runtime present, requesting install.
I don't want to install a new JDK. I can build the app in Android Studio. How can I use the JDK installed by Android Studio?
In this article you can find a solutiuon:
https://medium.com/#peter.configcat/build-your-android-app-from-command-line-with-android-studio-on-mac-ee1f7434709b
Add Android Studio JDK to your PATH. Add this to your .zshenv:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
export PATH=”$JAVA_HOME/bin:$PATH”
./gradlew tasks and ./gradlew assmebleDebug should work.

Unable to build android in IONIC 4 on MAC : ionic cordova build android

Unable to create build for android from Ionic 4 solution.
Command: ionic cordova build android
Error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/$USER/Library/Android/sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
I have android studio installed. I manually downloaded the gradle and kept in the path as well.
I have all the environment variables present. Still i have the same error message as shown above.
ENVIRONMENT VARIABLES
COMMAND: open ~/.bash_profile
export GRADLE_HOME=/Users/$USER/Library/Android/sdk/gradle/bin
export JAVA_HOME=/Users/$USER/Library/Java/Home
export ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
I tried the below link in ionic forum and many other but of no help:
https://forum.ionicframework.com/t/cannot-build-android-apk-ionic-4/184154
Any suggestions would be appreciated.
Thank you.
JAVA_HOME environment variable was incorrect due to multiple versions installed on my machine. I pointed it to the latest version and the issue is resolved.

Failed to find 'ANDROID_HOME' environment variable even when the variable is set Cordova

I am trying to create a mobile application from my angular app and am using cordova for converting the web app to mobile. I had followed all requirements given on the apache cordova official guide and installed Android studio as well using this online guide.
I had also followed this youtube tutorial which explained to easily convert the angular app into a cordova application using these steps:
- Create a cordova project within the angular project using cordova create <proj_name>
- Create a soft link, adding a link between www folder in cordova project and dist folder of angular project
- Create build
- Add android to cordova project
- Cordova run android
Everything goes fine until cordova run android where it gives me the following error:
Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
I checked to see on stackoverflow of any errors and there were in fact a few similar issues, which should have been resolved by editing the ~/.bashrc file and adding:
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
However, even after logging out and logging in again, several times, using source ~/.bashrc as well hasn't helped, the same error keeps popping up. I have also installed android studio and checked all paths the Sdk is installed and shows on the Sdk Manager in studio.
If I try to enter android in terminal it gives me an unknown command error, same goes with sdkmanager.
when I run echo $ANDROID_HOME it gives me the correct path:
/home/username/Android/Sdk
when I run cordova requirements it gives me the following:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
android: Command failed with exit code ENOENT
Gradle: installed /opt/gradle/gradle-5.2.1/bin/gradle
Some of requirements check failed
running cordova platform version android in the project gives the following:
form version android
Installed platforms:
android 8.1.0
Available platforms:
browser ^6.0.0
electron ^1.0.0
ios ^5.0.0
osx ^5.0.0
windows ^7.0.0
I do not understand what seems to be missing? I have looked several times but can't seem to find the problem with my installation. Am i doing something naive here?
For anyone facing the same issue: For some reason data was being fetched from npm cache. To clear it, simply:
sudo npm cache clean -f
Maybe not the best approach, but for now it was the only way out

Error prebuild react-native, build.gradle

When you first start the application, this error appears. I don't understand what it can be connected with.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\xxxx\android\app\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Malformed \uxxxx encoding.
Check the order of execution. I think your computer environment is Windows.
You recommend installing Node and Python2 via Chocolatey, a
popular package manager for Windows.
choco install -y nodejs.install python2 jdk8
If you have already installed Node on your system, make sure it is Node 8.3 or newer. If you already have a JDK on your system, make sure it is version 8 or newer.
Download and install Android Studio. Choose a "Custom" setup when
prompted to select an installation type. Make sure the boxes next to
all of the following are checked:
Android SDK
Android SDK Platform
Performance (Intel ® HAXM) (See here for AMD)
Android Virtual Device
Then, click "Next" to install all of these components.
Android Studio installs the latest Android SDK by default.
Building a React Native app with native code, however, requires the
Android 9 (Pie) SDK in particular. Additional Android SDKs can be
installed through the SDK Manager in Android Studio.
The SDK is installed, by default, at the following location:
c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk
Add platform-tools to Path
Open the System pane under System and Security in the Windows Control Panel, then click on Change settings.... Open the Advanced tab and click on Environment Variables.... Select the Path variable, then click Edit. Click New and add the path to platform-tools to the list.
The default location for this folder is:
c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\platform-tools
React Native has a built-in command line interface, which you can
use to generate a new project. You can access it without installing
anything globally using npx, which ships with Node.js.
npx react-native init AwesomeProject
Run npx react-native run-android inside your React Native project
folder:
cd AwesomeProject
npx react-native run-android
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
Go to your React-native Project -> Android
Create a file local.properties
Open the file
paste your Android SDK path like below
in Windows sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk
in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
in linux sdk.dir = /home/USERNAME/Android/Sdk
Replace USERNAME with your user name
Now, Run the react-native run-android in your terminal.

Error when build the phonegap android empty project?

I am trying to create a simple project in phonegap with association of wikitude.
This is the tutorial which I followed - wikitude + phonegap tutorial
And I am using ubuntu 12.04 these are the only steps which I followed,
$ npm install -g phonegap - Adding phonegap
npm install plugman - Adding plugman
sudo npm install -g cordova - installing codova
Then following steps to create app,
$ phonegap create MyAugmented - create app
$ phonegap build android - build in android
Aditionally I have installed android sdk using apt-get.
But when I build this app using above build command it gives an error,
Error in Text :
Error: An error occurred while listing Android targets
at /home/sachith/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
at /home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
at /home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
at flush (/home/sachith/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
{ [Error: /home/sachith/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8] code: 8 }
[error] /home/sachith/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8
Answers would be really appreciated,
Thanks in Advanced.
Most probable reason is you don't have latest android SDK. So update your android SDK and it should work fine.
You can reference this to see way of finding error.
Cordova has a script to check if all dependencies are present. Is is
called when you run cordova platform add android but unfortunatly it's
output is not displayed when it fails.
You can try to run it manually, it should be
$home/.cordova/lib/android/cordova/3.3.0/bin/check_reqs
The normal output when everything's fine is "Looks like your
environment fully supports cordova-android development!", oterwise it
should display a clear message about what's missing.
Maybe your issue is that you havent't installed SDK platform for API
19 in android sdk manager (cordova 3.3 uses target sdk 19).
UPDATE:
Android SDKs are updated using SDK Manager. You can see how to use SDK from here.
http://developer.android.com/tools/help/sdk-manager.html

Categories

Resources