我一步一步地遵循官方的Getting Started.我从一个干净的linux安装开始,按照"使用本机代码构建项目"选项卡安装了所有需要的东西.我还阅读了故障排除部分.我已经用终端创建了这个项目.

这是我运行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.

Duplicate disclaimer:我已经读了this question本了.这不是我想要的.我知道如何设置Java主页.我只想运行react项目,而不必安装单独的Java.

问题:

  1. 如何在Android Studio文件夹中找到内部Java,以便将Java_指向它的主页?
  2. 如果不可能,我可以用Android Studio打开并运行android文件夹中的项目吗?在修改父文件夹中的React JavaScript代码后,如何刷新此项目?

推荐答案

我将回答我自己的问题,并为我的linux用户同伴提供反馈:

1-要将JAVA_主页指向Android Studio附带的JRE,请首先找到Android Studio安装文件夹,然后找到/jre目录.该目录的完整路径就是您需要设置JAVA_路径的地方(感谢@TentenPonce的answer).

exp或t JAVA_HOME=<Your Android Studio path here>/jre

如果您遵循React Native Getting Started f或 Linux,则此文件(一个或另一个)与添加ANDROID_HOME的文件相同.默认情况下,两者都可以在您的主目录中找到,并且都可以隐藏.添加行后,需要重新加载终端,以便它可以拾取新的环境变量.So类型:

source $HOME/.bash_profile

source $HOME/.bashrc

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

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

2-因为react-native run-android似乎只是这样:

cd android && ./gradlew installDebug

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 emulat或. Type CTRL + M (CMD + M on MacOS) and select the "Enable live reload" option in the menu that appears (Kudos to @BKO f或 his answer)

Reactjs相关问答推荐

当我在React中使用类方法更新模型的状态时,它在严格模式下触发两次

如何在重新图表中更改悬停时的条形填充 colored颜色 ?

如何在Reac.js中通过子组件和props 调用父组件函数?

如何在整个应用程序中显示通用弹出窗口中的点击事件

子路径上未定义useMatches句柄

如何在REACTIVE js中动态添加或删除输入字段?

根据处于react 状态的数组的名称键,将新对象添加到嵌套的对象数组中

如何在React组件中自动更新图表数据?

React 无效的钩子调用:如何避免嵌套钩子?

Chakra UI:如何在选中状态下设置复选框 colored颜色

无法从子组件传递数据到父组件

React:如何使用条件渲染和react 挂钩来更新另一个组件的状态?

使用 map 循环浏览列表列表中的列表并显示它们

如果传递给挂钩的数据需要事先修改,如何使用自定义挂钩?

将 ref 赋予功能组件以使用内部功能

错误:无效挂钩调用.钩子只能在函数组件的主体内部调用.使用 next/router 时

如何从一组对象映射 MUI 5 图标并更改其 colored颜色 ?

模块解析失败:意外令牌 (257:106) 您可能需要适当的加载程序来处理此文件类型

.filter() 函数在删除函数中创建循环 - React

如何在 React JS 上使文本中的单词可点击