I'm working on MacOS and just starting with react-native
.
One of the first steps to get started is to run: react-native run-android
or react-native run-ios
. But I'm getting this error:
react-native run-android
Result:
Scanning folders for symlinks in /Users/ric/myprojs/albums/node_modules (6ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '9.0.1'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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
This is what I get when I run java --version
:
java --version
Result:
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
mbp:albums ric$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Edit
My javac version:
javac --version
Result:
javac 9.0.1
Any idea on how to fix this?
In your
PROJECT_PATH/android/gradle/wrapper/gradle-wrapper.properties
file, update yourdistributionUrl
to the following:See related gradle distributions documentation
Then add the following lines:
Now source the file to make the above changes effective in the current shell:
I was getting this error, but for a more recent version of Java - 10.0.2.
To fix my error, I followed the steps mentioned by
@Blacktoviche
in this Github issue: https://github.com/facebook/react-native/issues/17688When I opened the
android
folder inside my project via Android Studio, I was prompted withAndroid Gradle plugin update recommended
. At the time, I was following a slightly outdated tutorial that told me to clickDon't remind me again for this project
.However, as
@Blacktoviche
recommended in the github issue linked above, sometimes it's necessary to update the Gradle plugin. After updating, I also had to clickInstall Build Tools 27... and sync project
(I don't remember the exact version).After I followed these steps, I was able to successfully run my react native app on the Android Studio emulator.
Hope this helps someone!
I usually get this error when I forget to build the project using Android Studio. A simple sync and upgrading Gradle will do the work.
React Native does not work with Java versions higher than 8, so you need to uninstall your
9.0.1
version. To do so, execute the following commands:Identify the folder containing your Java Version, then remove it
After that you can download and install java 8 from oracle again. Refer to jdk8 download page
Make sure that you have
JDK8
installed and then setJAVA_HOME
intoJDK8
for example:
or use
.bash_*
files to set this variable