【发布时间】:2021-11-25 14:46:04
【问题描述】:
我已经为此烦恼了 3 天了,
每次我运行命令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 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,但在 compatibility docs 中它说:
执行 Gradle 需要 8 到 15 之间的 Java 版本。爪哇 16 执行 Gradle 时暂不支持及更高版本。
任何帮助都会非常真的感激!
【问题讨论】:
-
你能用你的终端试试“echo %JAVA_HOME%”命令吗?这很奇怪,因为它正在寻找 C:\Program Files\Java\jdk-17\bin\java.exe 而你的版本是 15 。
-
@George 它返回 `C:\Program Files\Java\jdk-15\bin`
-
可以分享一下 build.gradle 文件吗?甚至只是检查 sourceCompatibility 和 targetCompatibility 。你能检查一下你的 .gradle/gradle.properties 中是否有任何全局值吗?
-
@George 这是我的 build.gradle 文件的链接:justpaste.it/29x2w
-
提前感谢,很高兴我能帮上忙。
标签: java android react-native android-studio gradle