当我尝试在模拟器上 运行 时,React Native 失败

React Native Fails When I Try To Run on Emulator

今天我刚刚创建了我的第一个 React Native 项目,但是当我尝试 运行 它在我的 avd 上时就像;

react-native run-android

但它总是这样:

info JS server already running.
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)...
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:bundleDebugJsAndAssets SKIPPED
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :app:javaPreCompileDebug
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:mergeDebugResources
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk/jre contains a valid JDK installation.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 26s
12 actionable tasks: 5 executed, 7 up-to-date
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 app:installDebug. Run CLI with --verbose flag for more details.

我不知道该怎么办,我完全需要你的帮助。

感谢您的关注。

你好。您需要检查 JDK 是否正确安装并验证您是否添加了环境变量 JAVA_HOME & JDK_HOME.

系统查看 JRE 文件夹时出现问题,即 /usr/lib/jvm/java-8-openjdk/jre。如果我们查看那里,没有 Tools.jar,因此出现错误。

您可以创建环境变量 JAVA_HOME:

Variable value 中添加 JDK 代替 jdk1.8.0_11

现在编辑您的 PATH 变量以添加 JAVA_HOME :

现在再次尝试 运行 命令。

或者



检查此路径C:\Program Files\Android\Android Studio\jre\lib,如果在那里找到tools.jar,然后尝试在上面的环境变量中设置JAVA_HOME=C:\Program Files\Android\Android Studio\jre .

对于 Linux 用户 -

编辑系统路径文件/etc/profile

sudo gedit /etc/profile

在末尾添加以下行

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

代替 jdk1.7.0 添加您的 JDK 版本。
然后注销并登录 ubuntu 以设置路径...

希望有用!