React-Native ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.

2019-06-01 13:03   Tags:
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.
error 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
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.

运行react-native时候出现这个问题,

先检查是否已安装java jdk

并以配置好环境变量

git里下载:https://github.com/frekele/oracle-java/releases

不要去官网下载,速度慢成狗

配置环境变量

以win10为例

桌面》电脑》右击属性》高级系统设置》环境变量》系统变量

下面框里,我是已经添加好了

点击新建

变量名:JAVA_HOME

路径:根据自己安装目录

然后确定

在然后呢编辑path那个变量

先删除第一个,oracle/java之类的路径,java默认设置的

或者不删除,直接编辑,改成%JAVA_HOME%\bin,这个也行,

否则

点击新建

输入%JAVA_HOME%\bin

最后,确定,就行

记得重新打开cmd窗口,否则java还是没有找到

在运行react-native就成功了

发表评论

电子邮件地址不会被公开。 必填项已用*标注