执行时出现此错误
react-native run-android
我尝试将tools.jar文件复制到JRE安装位置,重新安装JDK和JRE,检查环境变量的路径。没事。
返回以下异常
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
> Task :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_211 contains a valid JDK installation
* 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.
答案 0 :(得分:11)
对于 MacOS,步骤如下:
$ java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
$ cd /Library/Java/JavaVirtualMachines
$ ls
total 0
drwxr-xr-x 3 root wheel 96B 24 Out 09:24 adoptopenjdk-15-openj9.jre
drwxr-xr-x 3 root wheel 96B 30 Dez 20:18 jdk1.8.0_271.jdk
$ cd jdk1.8.0_271.jdk/Contents/Home
注意:如果在列出文件夹中的文件后找不到1.8.0_271.jdk
,您可能会找到另一个类似这样的jdk文件adoptopenjdk-8.jdk
使用它。
$ pwd | pbcopy
org.gradle.java.home=<path_to_current_java_home>
她是一个工作示例:
答案 1 :(得分:0)
将此添加到 gradle.properties :
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_91
别忘了使用双反斜杠。例如:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144\
答案 2 :(得分:0)
这是因为无法检测到有效的 jdk 路径。转到您的项目,打开 android 文件夹 > gradle.properties 文件 > 添加以下行:
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
你很高兴;)