react-native 找不到 JAVA_HOME [英] react-native can not find JAVA_HOME
问题描述
使用 react-native init AwesomeProject
初始化我的项目后,我尝试通过 react-native run-android
在模拟器中运行它但是我收到以下错误:
After initializing my project with react-native init AwesomeProject
I try to run it in the simulator via react-native run-android
However I get the following error:
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 Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
但是我遵循了入门指南 和 JAVA_HOME Evironmental变量已设置,C:\Program Files\Java\jdk1.8.0_221\bin
也在路径变量中.
However I followed the Getting Started Guide and the JAVA_HOME Evironmental Variable is set and C:\Program Files\Java\jdk1.8.0_221\bin
is also in the Path var.
我正在使用 WSL bash 在 Windows 10 上尝试此操作.
I am trying this on Windows 10 with the WSL bash.
推荐答案
我能够通过创建一个新项目来解决这个问题.问题是我从 Windows 中的 WSL bash 运行 react-native init AwesomeProject
.我可以重现这一点.在命令提示符下运行相同的 init 命令时,它可以工作.
I was able to fix this by creating a new project. The problem was that I run react-native init AwesomeProject
from the WSL bash in windows. I could reproduce this.
When running the same init command in the command prompt it works.
这篇关于react-native 找不到 JAVA_HOME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!