react-native: Could not determine java version from '9.0.4'.

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: Linux 4.13 Node: 9.4.0 Yarn: Not Found npm: 4.6.1 Watchman: Not Found Xcode: N/A Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.52.0 => 0.52.0

Steps to Reproduce

  1. Plugged an Android phone, enabled developer mode and debugging and confirmed that adb is recognised the device by running adb devices
  2. Followed the official docs and created a react-native app called AwesomeProject using react-native init AwesomeProject command.
  3. Changed the directory to inside the project and ran react-native run-android

Expected Behavior

Start the AwesomeProject in connected Android Device.

Actual Behavior

Didn’t start the app on my mobile. Error on console appeared.

Scanning folders for symlinks in /home/pankaja/Documents/Projects/react-native/AwesomeProject/node_modules (7ms)
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.4'.

* 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
^C
pankaja@pankaja-HP-Pavilion-15-Notebook-PC:~/Documents/Projects/react-native/AwesomeProject$ react-native info

Screenshot

Reproducible Demo

react-native init AwesomeProject
cd AwesomeProject
react-native run-android

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 25 (2 by maintainers)

Most upvoted comments

just in case you need a quick fix, you can uninstall JDK 9 and install JDK 8 instead

Hey, I had the same issue. I went to the gradle. properties file and changed the version in the ‘distributionUrl’ field to the latest version.

distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

Try https://github.com/facebook/react-native/issues/16536 to edit the gradle-wrapper.properties

If any one came across this problem. you don’t have to downgrade java version Just import the android folder into Android studio it will ask you to update gradle click update and when it finish everything is working fine It worked for many for so many projects

Fixed the main error by installing JDK 8 instead

@TClark000 Thanks, I followed it and it worked.

Then another error occurred and fixed it by searching through Stackoverflow answers.

Now this error occurs.

Scanning folders for symlinks in /home/pankaja/Documents/Projects/react-native/AwesomeProject/node_modules (6ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

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.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
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

Couldn’t find a way to fix this.

Running with Java 8 works for me too – additionally don’t forget to set JAVA_HOME in your .bashrc to the value returned by /usr/libexec/java_home -v

I had same issue, on Mac. First thing I did was change distributionUrl to latest gradle, that created other issues, but following gradle upgrade guid, i solved them and landed on having xmlSchema issue described here. I didn’t want to take the risk of uninstalling jdk 9 and I found following SO question which describes how to manage multiple java version on Mac:

https://stackoverflow.com/questions/26252591/mac-os-x-and-multiple-java-versions

Using jenv, i set local java to java8 and everything worked as it should.

@kevinzhangftw Open Android Studio and click on ( Import project ) and select android folder in your react-native app

By using this way I built my react-native project using Java 10 too

I ask 4 other React Native dev. They all said they have downgraded their Java version to 8. For purpose of using react-native run-android. -Use Java 8. -Set ANDROID_HOME according to https://facebook.github.io/react-native/docs/getting-started.html -Set JAVA_HOME according to http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/

HI I have uninstalled with:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Java

and installed JDK8 but still getting the same error. How come? Thanks!

Done, add also: sudo rm -fr /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/

As @kate-kholyavkina suggested uninstall JDK 9 and install JDK 8 instead solved my issue.

@pankaja92 Could you please check you environment variables such as JAVA_HOME. (cmd: java -version) Also it would be nice to update gradle to 4.4+ version.