Cmd / React Native无法检测到我的JAVA_HOME环境变量

时间:2019-11-25 07:31:41

标签: android react-native

我正在尝试为Android创建一个React Native应用。我在Windows 10的命令行中使用bash。浏览到我的React Native项目的位置,然后运行“ react-native run-android”。但是然后我得到了这样的错误:

$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
/bin/sh: 1: adb: not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

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. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
    at checkExecSyncError (child_process.js:601:13)
    at execFileSync (child_process.js:621:13)
    at runOnAllDevices (/mnt/c/users/lenovo/documents/repositories/upself rn/upself/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

TL; DR,它告诉我设置JAVA_HOME的环境变量。 AFAIK。

问题是自从几个月前在笔记本电脑中安装Windows 10以来,我已经设置了JAVA_HOME。我使用JDK 12,并且使用同一台笔记本电脑使用Android Studio开发了一些本机Android应用程序,并且从未遇到任何遗漏的JAVA_HOME问题。

这是我试图解决此问题的方法:

  • 以管理员身份运行cmd

  • 将JAVA_HOME设置为c:\Program Files\Java\jdk-12.0.2\,并将其设置为Android Studio默认SDK位置C:\Users\lenovo\AppData\Local\Android\Sdk。两者都不起作用。

  • 重新启动笔记本电脑和cmd(已完成多次,但仍然无法正常工作)。

  • 在路径之间添加引号(在堆栈溢出问题中找到该引号)。

我在堆栈溢出中读了很多问题,但是这些都不起作用。

那么,有人可以帮助我解决这个问题吗?为什么无法检测到环境路径?

1 个答案:

答案 0 :(得分:1)

根据react native文档,您应该只安装JDK 8来运行react native应用

https://facebook.github.io/react-native/docs/getting-started

在安装Java并设置环境变量后,必须重新启动系统。

https://www.thewindowsclub.com/set-java_home-in-windows-10