当我尝试运行命令时:
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.htmlJAVA_HOME设置正确(我认为)
java -version 和
echo $JAVA_HOME 返回正确的结果。截图:

环境在/etc/ JAVA_HOME /etc/profile /bashrc /bash_profile中设置
我也做了/bashrc等源码
虚拟设备也已连接。我可以在android-studio中打开这个项目并生成apk
发布于 2019-04-21 22:17:53
确保已经安装了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发布于 2019-04-22 00:45:03
在linux中你不需要重启你的电脑,如果你有ubuntu或者一个衍生的包含路径的文件在/etc/enviroment中,检查这个文件看看JAVA_HOME是否设置在那里。
另外,你可能想要使用JDK8,因为JDK9和10与react native不能很好地协同工作。
然后关闭您的会话并重新登录
https://stackoverflow.com/questions/55778898
复制相似问题