首页 > 解决方案 > 当我尝试在模拟器上运行时,React Native 失败

问题描述

今天我刚刚创建了我的第一个 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.

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

感谢您的关注。

标签: javascriptreactjsreact-nativereact-native-androidavd

解决方案


系统查看 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以设置路径...

希望它有效!


推荐阅读