设置时未设置错误JAVA_HOME

时间:2019-04-21 00:29:31

标签: linux react-native

当我尝试运行命令时:

    react-native run-android

我收到此错误:

Scanning folders for symlinks in /home/x/myApp/node_modules 
(10ms)
JS server already running.
Building and installing the app on the device (cd android && 
./gradlew installDebug)...

ERROR: JAVA_HOME is not set and no 'java' command could be 
found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device 
connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

JAVA_HOME设置正确(我认为)

java -version 

echo $JAVA_HOME 

返回正确的结果。屏幕截图: 1 JAVA_HOME在/ etc / environment / etc / profile / bashrc / bash_profile

中设置

我也提供了/ bashrc等

虚拟设备也已连接。我可以在android-studio中打开该项目并生成apk

2 个答案:

答案 0 :(得分:2)

确保已安装Java

之后

如果您的路径错误 做到这一点:

export | grep JAVA

结果:java home设置为

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

按照路径查看目录是否正确 我在我的终端上做到了:

open /Library

然后我去了/ Java / JavaVirturalMachines,结果发现我有错误的“ jdk1.8.0_202.jdk”文件夹,还有另一个数字... 4.您可以使用此命令设置java_home

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home

答案 1 :(得分:0)

在linux中,您无需重新启动PC,如果您具有ubuntu或衍生版本,则包含PATH的文件位于/ etc / enviroment中,请检查该文件以查看是否在其中设置了JAVA_HOME。

另外,您可能想使用JDK8,因为JDK9和10不能与本机反应很好。

然后关闭您的会话并再次登录