react-native run-android won't work with Oracle Java 9

Created on 6 Jan 2017  路  8Comments  路  Source: facebook/react-native

Description

I followed the Getting Started and typed the following commands as described in the doc:

$ react-native init AwesomeProject

Output: https://gist.github.com/guilhermednt/bbc1ba43c298341acc5a7e5293414fa5

$ react-native run-android
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-ea'.

* 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

(running with --stacktrace, --info and --debug won't work)

I'm not familiar with React or Gradle but after looking around I found out it could be a Gradle problem.
I changed android/gradle/wrapper/gradle-wrapper.properties to try to make it use Gradle 3.3 and the error changed to:

$ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
java.lang.ExceptionInInitializerError (no error message)

* 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

Reproduction

Just follow the steps from the Getting Started:

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

Solution

Fix the docs explaining the correct way to get started or fix whatever is causing this error.

Additional Information

  • React Native version: 0.40.0 (cli 2.0.1)
  • Platform: Android
  • Operating System: Linux - elementary OS - 4.4.0-36-generic
  • JAVA_HOME: /usr/lib/jvm/java-9-oracle
  • ANDROID_HOME: /home/my_user/Android/Sdk
Ran Commands Locked

Most helpful comment

Any update on this?

All 8 comments

Today I tried it again but using Oracle Java 8 and it worked. So another "solution" might be to require Java 8?

The Android build tools only support JDK 1.7 & 1.8 currently.

The setup guide already specifies that it requires JDK 1.8:

Android Studio requires the Java SE Development Kit(JDK), version 8. You can type javac -version in a terminal to see what version you have, if any.
https://facebook.github.io/react-native/docs/getting-started.html

@facebook-github-bot answered

Closing this issue as @AndrewJack says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

Alright well i'm having the same problem how do i make the react-native reference java 8 now that i have already reference java 9 ??

I tried changing the version by doing this
sudo update-java-alternatives --set java-8-oracle

then checking the version with
javac -version

it returns javac 1.8.0_131

But when i echo $PATH i see that it is still referencing the java 9 folder

echo $PATH /home/andrei/.nvm/versions/node/v7.5.0/bin:/home/andrei/bin:/home/andrei/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-9-oracle/bin:/usr/lib/jvm/java-9-oracle/db/bin:/home/andrei/Android/Sdk

how do i change that?

Any update on this?

Change the environment variables PATH and JAVA_HOME in your OS. In windows you do that by searching for "Environment Variables" or right mouse button on This PC / Properties / Advanced...

Was this page helpful?
0 / 5 - 0 ratings