报错信息
> Task :@react-native-community_async-storage:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':@react-native-community_async-storage:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.
解决方法:
步骤1:
打开/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home文件夹,发现文件夹下没有tools.jar文件
步骤2:
卸载jdk
参考https://blog.csdn.net/jacy0115/article/details/98626433
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefpane
ls /Library/Java/JavaVirtualMachines/
结果是jdk1.8.0_231.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk
卸载完毕
步骤3:
重新下载安装jdk
步骤4:
配置JAVA_HOME
(1)输入命令
open -e .bash_profile
(2)在打开的文件中增加JAVA_HOME的配置,jdk1.8.0_271.jdk根据自己的安装版本
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
(3)使用source .bash_profile使配置生效
source .bash_profile
(4)输入 echo $JAVA_HOME 看下配置是否生效
echo $JAVA_HOME
(5)再次运行react-native run-android
注意!!!
这里有问题
两台电脑,1台按上面的步骤有效,1台没有效果
如果没有效果
运行已下代码就可以了
source .bash_profile & react-native run-android
2次注意!!!
后来又遇到这个问题了,不用卸载重新安装,关闭终端,重新打开终端
1、先执行echo $JAVA_HOME,发现是空
2、再执行source .bash_profile,再执行echo $JAVA_HOME,发现不是空了
3、在运行react-native run-android或者cd android && ./gradlew assembleRelease就可以了