我已經拉了三天的頭發了,
每次運行命令時react-native run-android都會出現此錯誤:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
(node:10284) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Jetifier found 871 file(s) to forward-jetify. Using 16 workers...
info JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk-17\bin\java.exe
* 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
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Java\jdk-17\bin\java.exe
* 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
at makeError (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\execa\index.js:174:9)
at C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\execa\index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5)
at async Command.handleAction (C:\Users\username\Desktop\code\React Native\Build App\Scheduler\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:192:9)info Run CLI with --verbose flag for more details.
我使用基本創建了我的目錄 react-native init projectTesting
我的 gradle 是 6.9 版
.\android\gradle\wrapper\gradle-wrapper.properties=>distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
我的 android studios 版本是 Android Studio 2020.3.1
我的java版本是15
C:\Users\username>java -version
java version "15" 2020-09-15
Java(TM) SE Runtime Environment (build 15 36-1562)
Java HotSpot(TM) 64-Bit Server VM (build 15 36-1562, mixed mode, sharing)
C:\Users\username>javac -version
javac 15
我正在考慮使用 java 17 但在兼容性檔案中它說:
執行 Gradle 需要 8 到 15 之間的 Java 版本。執行 Gradle 時尚不支持 Java 16 及更高版本。
任何幫助將非常感謝!
uj5u.com熱心網友回復:
確保您的終端中的 JAVA_HOME 路徑
echo %JAVA_HOME%
擁有 \bin 是一個常見的錯誤,而 \bin 應該在 PATH 中,java home 只是你的 jdk 檔案夾,如 C:\Program Files\Java\jdk-15 。
洗掉 jdk-17 檔案夾,然后卸載 31 和 30 版本的 sdk 構建工具,這應該可以解決問題。
很高興我有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/311281.html
