React-Native run-android command cannot find Android Studio and SDK - android

I am building a React-Native project on Mac OS. My Mac is Mac Mini which is using the new Apple M1 chip. I can build and run my project on iOS simulator using "react-native run-android" command. But when I run "react-native run-android" command, it is not working.
I downloaded and installed the Java JDK. When I type in "java -version" in the terminal, I can see the following output.
openjdk version "17" 2021-09-14 LTS
OpenJDK Runtime Environment Zulu17.28+13-CA (build 17+35-LTS)
OpenJDK 64-Bit Server VM Zulu17.28+13-CA (build 17+35-LTS, mixed mode, sharing)
Then I downloaded and installed the latest version of Android Studio. It is installed and Android SDK is located in the following path.
/Users/waihein/Library/Android/sdk
I have the following content in the ~/.hash_profile file.
export PATH="/usr/local/bin:$PATH"
export ANDROID_HOME=/Users/waihein/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:/Users/waihein/Library/Android/sdk/platform-tools/
Within my react-native project folder, when I run "react-native run-android", I got the following output.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.8/userguide/gradle_daemon.html
Process command line: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /Users/waihein/.gradle/wrapper/dists/gradle-6.8-all/9emh0d32e025cam7aasxcw002/gradle-6.8/lib/gradle-launcher-6.8.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.8
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
I tried using "sudo react-native run-android" too, I got the same error.
When I run "react-native doctor" command, I got the following output.
But I installed the Android studio correctly. What is wrong with my configuration or installation and how can I fix it?

Although the react native docs don’t specify a range of JDK versions that work with RN, I personally haven’t been able to get anything but OpenJDK8 to work. Try installing that and setting the JAVA_HOME environment variable to its path.
I think the package for it got renamed recently in Homebrew - you’d run ‘brew install temurin8’ now.

Related

Is React Native 0.63.3 Android can't be run on Mac Mini M1?

My goal is to run an old project. It uses React Native 0.63.3. This is the repository
What I've did:
Setup the environment by following the docs for 0.63
Installed Android Studio a month ago.
did $ brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
did not do $ brew install node because it is already installed.
did $ brew install watchman
Installed Android SDK Platform 29 on Android Studio.
Installed Google APIs ARM 64 v8a System Image under the Android 10 (Q) entry because I use Mac Mini M1 instead of Google APIs Intel x86 Atom System Image not documented on the docs for 0.63
Installed Android SDK Build-Tools 29.0.2 on Android Studio.
Added environment to ~/.zprofile and did $ source ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
export ANDROID_HOME=/Volumes/T7Touch/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
JAVA_HOME is not documented on the docs for 0.63, this is to fix cd android && ./gradlew clean issue
Then, I tried to run it by $ npm run android
However, it throws an error
...
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 39s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01

react-native program is not installed on the emulator

I created a new project with React Native in Windows 10 but it does not run with the run-android command.
I will summarize what I did because I think all the programs are installed:
I install both npm and node.
Java installation.
React installation.
In the Environment system, these are set.
ANDROID_HOME ---> C:\Users\IHC\AppData\Local\Android\Sdk
JAVA_HOME--> C:\Program Files\Java\jdk-۱۴.۰.۱
path--> C:\Users\IHC\AppData\Local\Android\Sdk\tools
C:\Users\IHC\AppData\Local\Android\Sdk\platform-tools
C:\Program Files\nodejs\
C:\Users\IHC\AppData\Local\Android\Sdk
C:\Users\IHC\AppData\Local\Android\Sdk\emulator
C:\Program Files\Java\jdk-۱۴.۰.۱\bin
The error is:
info Starting JS server...
info Installing the app...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
.
.
.
.
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:832)
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 44s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
enter code here
Can you check on the android version installed, for latest version refer https://www.npmjs.com/package/#react-native-community/cli-platform-android and retry.
That is installed, well I did the following
remove jdk-۱۴.۰.۱ and i install jdk-8u261-windows-x64
first of all run Oracle VM VirtualBox next run Genymotion
and in powershell
npm start -- --reset-cache
npm install -g npm#4
react-native run-android

ERROR: An error occurred while running subprocess cordova

I build an app on Ionic framework, it works on the browser but when I try to compile it on the emulator I have got this error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\user\AppData\Local\Android\Sdk (DEPRECATED)
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.3.1/userguide/gradle_daemon.html
Process command line: C:\Program Files (x86)\Java\jdk1.8.0_201\bin\java.exe -Xmx2048m -Dfile.encoding=windows-1252 -Duser.country=SA -Duser.language=ar -Duser.variant -cp C:\Gradle\gradle-5.3.1\lib\gradle-launcher-5.3.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.3.1
Please read the following process output to find out more:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
C:\Gradle\gradle-5.3.1\bin\gradle: Command failed with exit code 1
[ERROR] An error occurred while running subprocess cordova.
cordova run android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
This is because the path to Android Sdk is not set correctly. Please check the correct path for Sdk, tools, platform-tools, emulator and Android build-tools.
Please, realize that the configuration recommended for Ionic has changed a
bit. Now the notation recommended is as follows:
ANDROID_SDK_ROOT=/home/username/Android/Sdk (recommended setting)
ANDROID_HOME=/home/username/Android/Sdk (DEPRECATED)
In Linux or Mac OS X configure the path into the ~/.bashrc, ~/.bash_profile file:
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools
At the end, after save the configuration dont forget to do the command:
source ~/.bashrc
or as your case
source ~/.bash_profile
For the Windows users check the global variables.
Try to Run npm cache clean and re-install cordova...worked for me.
I finally found the solution from a related solved topic: The solution is:
ionic platform rm android
ionic platform add android#latest
ionic resources
ionic run android
ionic repair worked for me. Just give it a try and see if that works for you. Good luck!

Failed to notify project evaluation listener > javax/xml/bind/annotation/XmlSchema

I trying to first run an react-native app with react-native run-android. I expect it to work, like it does when I call react-native run-ios.
Have a lot of users with same kind of error here on stack, "Failed to notify project evaluation listener".
Observed Behavior
> react-native run-android
Scanning folders for symlinks in /Users/tiagogouvea/www/go-along/mobile/node_modules (12ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.gradle.internal.reflect.JavaMethod (file:/Users/tiagogouvea/.gradle/wrapper/dists/gradle-4.0-milestone-1-all/2rnr7rhi2zsmkxo9re7615fy6/gradle-4.0-milestone-1/lib/gradle-base-services-4.0.jar) to method java.lang.ClassLoader.getPackages()
WARNING: Please consider reporting this to the maintainers of org.gradle.internal.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /Users/tiagogouvea/Library/Android/sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> javax/xml/bind/annotation/XmlSchema
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 4s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
Environment
npm ls react-native-scripts: empty
npm ls react-native: react-native#0.50.3
npm ls expo: empty
node -v: v8.0.0
npm -v: 5.5.1
yarn --version: 1.2.1
watchman version: 4.9.0
Operating system: macOs 10.12.6
Phone/emulator/simulator & version: Genymotion image
As mentioned in a comment to the bug filed by OP, Gradle seems to have issues with Java 9 or later.
You need to install JDK 8 (JRE is not enough, and versions later than 8 will not work) and tell Gradle to use it, not the default Java version on your system.
In my case (running Ubuntu 18.04), this required installing openjdk-8-jdk (I already had JDK 11 and JRE 8 but not JDK 8).
You have several ways of telling Gradle to use JDK 8 (in all examples, replace the path with the actual path to your JDK installation; the one shown here is valid for Ubuntu 18.04 amd64):
Run Gradle with the option
-Dorg.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
Ensure ~/.gradle/gradle.properties contains the line
org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64
In your build.gradle include the following lines:
compileJava.options.fork = true
compileJava.options.forkOptions.executable = /usr/lib/jvm/java-8-openjdk-amd64
That has helped me get rid of the same error on a different project.
In fact I was running Java 9, running a java --version gave me:
$: java --version
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
To solve it completely I did:
1) Removed Java 9:
sudo rm -rf "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
sudo rm -rf "/Library/PreferencePanes/JavaControlPanel.prefPane"
sudo rm -rf "~/Library/Application Support/Java"
2) Installed back Java 8 - download here
3) Added JAVA_HOME line to my bashfile (~/.bash_profile):
nano ~/.bash_profile
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
* Pay attention to use right jdk version on path
And, everything wokrs fine now. Thanks for help #user149408!
I've resolved this issue by cleaning all the Gradle cache, stoping the Gradle Daemon process, and created a new build successfully using the following command. Make sure your current directory is android.
rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease

Execution failed for task ':CordovaLib:compileDebugJava'

I want to run my ionic app in android emulator. When I try to build ionic app using the following command in terminal:
ionic build android
It shows the following error ::
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':CordovaLib:compileDebugJava'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 20.383 secs
/home/meutics/ionicapp/ebook- app/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/meutics/ionicapp/ebook-app/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/meutics/ionicapp/ebook-app/platforms/android/build.gradle,-Dorg.gradle.daemon=true
Seems JAVA_HOME is not correctly configured, but I think I configure JAVA_HOME correctly.
In terminal window, I run the following command ::
meutics#meutics-pc:~$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64
In .bashrc window,vi ~/.bashrc
export PATH=$PATH:/home/meutics/Downloads/android-studio/bin
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export PATH=$PATH:$JAVA_HOME/bin
export ANDROID_HOME=/home/meutics/Android/Sdk
export PATH=$PATH:$ANDROID_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/build-tools
How can I solve this problem?
NB: In /usr/lib/jvm/ directory,
root#meutics-pc:/usr/lib/jvm# ls
java-1.7.0-openjdk-amd64 java-7-openjdk-amd64 java-8-oracle
And java version ::
meutics#meutics-pc:$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
just restart your CLI/ terminal and run as admin or do sudo on linux ... it worked for me

Categories

Resources