Home > Software engineering >  React-Native run-android command cannot find Android Studio and SDK
React-Native run-android command cannot find Android Studio and SDK

Time:09-21

I am building a React-Native project on Mac OS. My Mac is Mac mini which is using 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. Please, see what I have done so far below.

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.

enter image description here

But I installed the Android studio correctly. What is wrong with my configuration or installation and how can I fix it, please?

CodePudding user response:

First Setup Environment path for Android Studio

export ANDROID_HOME=$HOME/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

for more information about setup go through below link

Click hear

CodePudding user response:

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