facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.12k stars 24.32k forks source link

Could not determine java version from '9.0.4'. #17688

Closed thidasapankaja closed 6 years ago

thidasapankaja commented 6 years ago

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
irwanayeah commented 6 years ago

I have same problem

Environment: OS: Windows 10 Node: 7.10.1 Yarn: Not Found npm: 4.2.0 Watchman: Not Found Xcode: N/A Android Studio: Not Found

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

TClark000 commented 6 years ago

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

thidasapankaja commented 6 years ago

@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.

katerynajeeva commented 6 years ago

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

fragaLY commented 6 years ago

@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.

thidasapankaja commented 6 years ago

As @kate-kholyavkina suggested I removed and installed JDK 8. But now I'm getting another error. @fragaLY I just removed and installed JDK 8 and now when I run java -version this is what I get.

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

And now when I run react-native run-android in my project folder, I'm getting this error.


File /home/pankaja/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 23.0.1 in /home/pankaja/Android/Sdk/licenses
Warning: License for package Android SDK Build-Tools 23.0.1 not accepted.
Checking the license for package Android SDK Platform 23 in /home/pankaja/Android/Sdk/licenses
Warning: License for package Android SDK Platform 23 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 23, Android SDK Build-Tools 23.0.1].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

* 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 54s
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
thidasapankaja commented 6 years ago

Fixed the main error by installing JDK 8 instead

ykelanemer commented 6 years ago

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

samaitra commented 6 years ago

Hi

Following this guides helped me build the app in jdk9

https://github.com/gradle-guides/building-java-9-modules

HTH Regards Saikat

azmanahmed21 commented 6 years ago

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

neara commented 6 years ago

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.

smakosh commented 6 years ago

@kate-kholyavkina's solution worked fine!

dhcmega commented 6 years ago

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/

dchersey commented 6 years ago

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

TheGreatAndrew commented 6 years ago

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/

karna41317 commented 6 years ago

downgrade to java8 and set JAVAHOME in .bash* works

LordST95 commented 6 years ago

just for some up the quick way (removing jdk9), run these commands:

sudo apt-get purge openjdk-9-jre-headless sudo apt-get purge openjdk-9-jdk

Blacktoviche commented 6 years ago

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

kevinzhangftw commented 6 years ago

not sure what u mean by 'import the android folder into Android studio'

Blacktoviche commented 6 years ago

@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

cassiehilton commented 6 years ago

Thank you Blacktoviche! Great advice and it worked!

hyochan commented 6 years ago

@Blacktoviche But then, we need to upgrade all projects first to actually begin editing the codes...

djcurtin commented 6 years ago

Not to begin editing code; just to be able to run it on an emulator. It's an inconvenience, but not a huge one. And I doubt this is seen as the solution moving forward; likely a solution right now, and will be resolved in updates.

asatalkar-ttm commented 5 years ago

This is resolved by switching to lower Java SDK. As soon as I switch to 1.8 from 1.9 in Intellij and point my redirect my "PATH=%JAVA_HOME%\bin" in terminal, everything starts working!

hmsmurtaza commented 5 years ago

switching from java 9 to 8 resolved my issue