Could not determine java version from '11.0.1' when running "npm run android"

Viewed 6478

I'm trying to run react native on windows 10. when I run npm run android i get this following error

Starting JS server... Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

  • What went wrong: Could not determine java version from '11.0.1'.

  • 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 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/getting-started.html

3 Answers

Make sure you have set the necessary paths for Android and Java in your shell.

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
ANDROID_HOME=/Users/username/Library/Android/sdk
ANDROID_NDK_HOME=/Users/username/Library/Android/sdk/ndk-bundle

Also, sometimes react-native versions may get messed up with the Java versions so it's not so recommended to use Java SDK 11 just yet, so better Java 8 which it's a more stable version.

Try to uninstall the Java SDK 11 and install Java 8, then update your paths in your shell config to match the correct locations, then try again and your app should work like expected.

If you installed Java through homebrew try:

brew cask uninstall java
brew tap caskroom/versions
brew cask install java8

And you're done.

If you installed it directly try rm -rf /Library/Java/JavaVirtualMachines/jdk<version>.jdk to remove it and then download Java 8 either directly or through homebrew (recommended).

TL; DR Downgrade your Java version to Java 8.

Sometime between Java 9 and Java 11, the format of java -version has changed, resulting in breakage in Gradle.

Gradle like the 1.x versions:

As I tested:

λ ~/m-demo/ master jenv versions
  system
  11.0
  11.0.1
  1.8
* 1.8.0.191 (set by ~/.jenv/version)
  openjdk64-11.0.1
  openjdk64-1.8.0.191
Related