今天我刚刚创建了我的第一个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.
我不知道该怎么办,我完全需要您的帮助。
感谢您的关注。
答案 0 :(得分:0)
嗨。您需要检查是否已正确安装JDK,并确认已添加环境变量 JAVA_HOME 和 JDK_HOME 。
答案 1 :(得分:0)
系统查看JRE文件夹即/ usr / lib / jvm / java-8-openjdk / jre时出现问题。如果我们在那里查看,则没有Tools.jar,因此会出现错误。
您可以创建环境变量JAVA_HOME:
在Variable value
内添加您的JDK代替 jdk1.8.0_11
现在尝试再次运行该命令。
或
如果在此处找到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以设置路径...
希望它能起作用!