1

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.

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
  • The error seems to be `Unrecognized VM option 'MaxPermSize=512m'`. As per the question here: https://stackoverflow.com/questions/22634644/java-hotspottm-64-bit-server-vm-warning-ignoring-option-maxpermsize support for this flag was removed. Can you try replacing the argument as described in the answer inside your `/app/android/gradle.properties`? – nbokmans Sep 20 '21 at 21:02
  • But how can I remove it on Mac? – Wai Yan Hein Sep 20 '21 at 21:12
  • Hello, I still cannot find the option to set it on Mac. Could you please help? – Wai Yan Hein Sep 21 '21 at 19:06
  • You need to open the file I specify (`app/android/gradle.properties`). Inside there, there's a line `org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 `. Remove the `-XX:MaxPermSize=512m` part from the line, or look in the question I linked in previous comment to see what to replace it with. – nbokmans Sep 22 '21 at 12:17
  • Thanks. But I am getting this error this time. A problem occurred evaluating settings 'sharkyamalapp'. > Could not open dsl generic class cache for script '/Users/waihein/Desktop/Code/shar-kya-mal-app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' (/Users/waihein/.gradle/caches/6.8/scripts/a43tr593rdpk11ispliu0nu14). > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61 – Wai Yan Hein Sep 22 '21 at 17:25
  • Hi could you also please have a look at this question? https://stackoverflow.com/questions/69327249/react-native-run-android-on-applie-m1-chip-throwing-error-could-not-open-dsl-g. – Wai Yan Hein Sep 25 '21 at 14:51

1 Answers1

0

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.

suicune
  • 114
  • 3