React Native:未设置JAVA_HOME并且在您的PATH中找不到'java'命令 [英] React Native: JAVA_HOME is not set and no 'java' command could be found in your PATH

查看:372
本文介绍了React Native:未设置JAVA_HOME并且在您的PATH中找不到'java'命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已逐步遵循官方入门.我从干净的linux安装开始,并按照使用本机代码构建项目"选项卡安装了所需的所有内容.我还阅读了疑难解答部分.我已经使用终端创建了项目.

I've followed step by step the official Getting Started. I started from a clean linux install and installed everything required as per the "Building Projects with Native Code" tab. I have also read the troubleshooting section. I've already created the project using the terminal.

这是我运行react-native run-android时的错误:

    Starting JS server...
    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/android-setup.html

它找不到JAVA_HOME,因为最新版本的Android Studio不需要在系统中安装Java.而是使用内部JRE.

It does not find JAVA_HOME because the latest versions of Android Studio don't require Java to be installed in the system. Instead an internal JRE is used.

重复的免责声明:我已经阅读了

Duplicate disclaimer: I've already read this question. This is not what I want. I know how to set the Java home. I just want to run the react project WITHOUT having to install a separate Java.

问题:

  1. 如何在Android Studio文件夹中找到内部Java,以便可以将JAVA_HOME指向它?
  2. 如果不可能,我是否可以使用Android Studio在android文件夹中打开并运行该项目?修改父文件夹中的React JavaScript代码后,如何刷新该项目?
  1. How could I find the internal Java inside the Android Studio folder so that I could point JAVA_HOME to it?
  2. If not possible, could I open and run the project inside the android folder with Android Studio? How would I refresh this project after modifying the React JavaScript code in the parent folder?

推荐答案

我将回答自己的问题,并为我的Linux用户提供便利:

I'll answer my own questions and sponfeed my fellow linux users:

1-要将JAVA_HOME指向Android Studio随附的JRE,请首先找到Android Studio安装文件夹,然后找到/jre目录.该目录的完整路径是将JAVA_PATH设置为所需的路径(感谢@TentenPonce的 answer ). 在Linux上,您可以通过将以下行添加到.bashrc.bash_profile files中来设置JAVA_HOME:

1- To point JAVA_HOME to the JRE included with Android Studio first locate the Android Studio installation folder, then find the /jre directory. That directory's full path is what you need to set JAVA_PATH to (thanks to @TentenPonce for his answer). On linux, you can set JAVA_HOME by adding this line to your .bashrc or .bash_profile files:

export JAVA_HOME=<Your Android Studio path here>/jre

此文件(一个或另一个)与添加ANDROID_HOME的文件相同(如果您遵循Linux的React Native入门).两者都是默认隐藏的,可以在您的主目录中找到.添加该行之后,您需要重新加载终端,以便它可以接收新的环境变量.所以输入:

This file (one or the other) is the same as the one you added ANDROID_HOME to if you were following the React Native Getting Started for Linux. Both are hidden by default and can be found in your home directory. After adding the line you need to reload the terminal so that it can pick up the new environment variable. So type:

source $HOME/.bash_profile

source $HOME/.bashrc

,现在您可以在同一终端上运行react-native run-android.另一种选择是重新启动操作系统.其他终端可能工作方式不同.

and now you can run react-native run-android in that same terminal. Another option is to restart the OS. Other terminals might work differently.

注意:要使该项目真正运行,您需要提前启动一个Android模拟器,或者连接一个真实的设备.最简单的方法是打开一个已经存在的Android Studio项目并从那里启动模拟器,然后关闭Android Studio.

NOTE: for the project to actually run, you need to start an Android emulator in advance, or have a real device connected. The easiest way is to open an already existing Android Studio project and launch the emulator from there, then close Android Studio.

2-因为react-native run-android似乎要做的就是这样:

2- Since what react-native run-android appears to do is just this:

cd android && ./gradlew installDebug

您实际上可以使用Android Studio打开嵌套的android项目并手动运行它.如果您在启用实时重新加载中,可以重新加载JS更改模拟器.键入CTRL + M(在MacOS上为CMD + M),然后在出现的菜单中选择启用实时重载"(对于答案)

You can actually open the nested android project with Android Studio and run it manually. JS changes can be reloaded if you enable live reload in the emulator. Type CTRL + M (CMD + M on MacOS) and select the "Enable live reload" option in the menu that appears (Kudos to @BKO for his answer)

这篇关于React Native:未设置JAVA_HOME并且在您的PATH中找不到'java'命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆