React Native error: “Could not determine java vers

2020-01-25 04:44发布

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?

11条回答
▲ chillily
2楼-- · 2020-01-25 05:10

On MacOS, I ran the following commands:

brew cask uninstall java
brew tap caskroom/versions
brew cask install java8 "or just brew cask install java to install latest version"
查看更多
Lonely孤独者°
3楼-- · 2020-01-25 05:14

Really the fastest way to get around this error is to use JDK 8. Except when you really need to use JDK9.

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Don't forget to change your enviroment variable JAVA_HOME to the new JDK version!

查看更多
男人必须洒脱
4楼-- · 2020-01-25 05:14

I solve this by downgrading my JDK to 8.

查看更多
一纸荒年 Trace。
5楼-- · 2020-01-25 05:17

On Ubuntu, you should run these command lines in the terminal:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default
查看更多
混吃等死
6楼-- · 2020-01-25 05:18

If you are using windows; Make sure you add your jdk path to the Environment path variable. Then open your android folder from your react native project into android studio. It will update necessary things for you automatically.

查看更多
登录 后发表回答