问题描述
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-linear-gradient:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
当我升级到 Mac os Big sur 并运行时,
When I upgraded to Mac os Big sur and run,
npx react-native run-android
我收到此错误 (Android).我尝试了 Stack Overflow 的很多解决方案,但都没有奏效.
I got this error (Android). I have tried a lot of solutions from Stack Overflow, but none of them worked.
我创建了一个新项目并且它正在运行.此外,一些旧项目也运行良好.
I have created a fresh project and it's working. Also some of the old projects are also working perfectly.
*react-native Version: "0.63.3",*
请帮我找到解决方案?
推荐答案
问题在于更新时内置 java 优先,它没有 SDK,因为它只是运行时.
The problem is that with the update the built-in java took precedence and it doesn't have the SDK because it's just the runtime.
您只需要更改您的 java home 并将 java 二进制文件添加到您的 .zshrc找到你的 java home 执行:
You just need to change your java home and add the java binary to your .zshrcto find your java home execute:
/usr/libexec/java_home -V | grep jdk
输出应类似于以下内容:
the output should be similar to the following:
Matching Java Virtual Machines (1):
1.8.0_272 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
在我的情况下,您应该采用 SDK 的路径
you should take the path from the one that says SDK in my case
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
之后,您只需将以下内容添加到应该在您家中的 .zshrc 的末尾.
after that, you just add the following to the end of your .zshrc that should be in your home.
您可以编辑它(如果您决定使用 vim,您可以退出编写 :wq! 并按 Enter)
You can edit it with (if you decide to use vim you can exit writing :wq! and pressing enter)
vim .zshrc
添加以下内容:
export JAVA_HOME=the/path/you/copied/before
export PATH=$JAVA_HOME/bin:$PATH
在我的情况下,/path/you/copyed/before 在哪里
where the/path/you/copied/before in my case would be
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
保存文件并关闭所有终端并再次打开它们.
save the file and close all your terminals and open them again.
如果在编辑 .zshrc 文件时出现错误.zshrc";E212: 无法打开文件进行写入然后使用 sudo vim.zshrc 就可以编辑了.
If while editing .zshrc file getting error ".zshrc" E212: Can't open file for writingthen use sudo vim.zshrc and you'll be able to edit.
应该解决错误.
这篇关于找不到 tools.jar.请检查/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 是否包含有效的 JDK 安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!