2017-10-21 20 views
32

Tôi đang làm việc trên MacOS và chỉ bắt đầu với react-native.Lỗi gốc phản ứng: "Không thể xác định phiên bản java từ '9.0.1'."

Một trong những bước đầu tiên để bắt đầu là chạy: react-native run-android hoặc react-native run-ios. Nhưng tôi nhận được lỗi này:

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

Đây là những gì tôi nhận được khi tôi chạy java --version:

$ 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) 
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) 

EDITED: Đây là những gì tôi nhận được khi tôi chạy javac --version:

$ javac --version 
javac 9.0.1 

Bất kỳ ý tưởng nào về cách sửa lỗi này?

+2

bạn có thể chạy 'javac -version' quá trong thiết bị đầu cuối, vui lòng – bennygenel

+0

Tôi vừa chỉnh sửa câu hỏi của mình với kết quả của lệnh đó. Cảm ơn! – Xar

+1

Tôi tìm thấy [vấn đề này] (https://github.com/facebook/react-native/issues/11755) nó là một chút cũ nhưng có thể liên quan đến một trong hai phiên bản java hoặc gradle. – bennygenel

Trả lời

54

Trong tập tin,

PROJECT_PATH/android/gradle/wrapper/gradle-wrapper.properties

Cập nhật distributionUrl của bạn như sau

distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-rc-2-all.zip 
+0

Tôi có thể tìm thấy tệp 'gradle.wrapper.properties' ở đâu? Cảm ơn – Xar

+2

phải ở trong ** thư mục ứng dụng/android/gradle/wrapper/gradle-wrapper.properties ** –

+0

Cảm ơn bạn! Điều đó đã khắc phục được vấn đề của tôi. Đối với một số lý do tôi đã có phiên bản cũ 'gradle-2.14.1-all.zip' – Xar

1

Bạn nên chạy những dòng lệnh trong 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

hãy chắc chắn rằng bạn có JDK8 cài đặt và sau đó thiết lập JAVA_HOME vào JDK8

ví dụ:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home 

hoặc sử dụng .bash_ * tệp để đặt biến này

Các vấn đề liên quan