javascript - 当我尝试在模拟器上运行时,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.
我不知道该怎么办,我完全需要你的帮助。
感谢您的关注。
解决方案
系统查看 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以设置路径...
希望它有效!
推荐阅读
- sql - 通过数据库上下文将空 DataTable 传递给 SQL Server 存储过程
- python - Jupyter 内核状态“未知”,或在将多个单元排队以进行运行时“正在连接”
- ios - 在 SwiftUI 中创建局部视图控制器
- python - 元组的类型提示,如果参数的数量可以是 2 或 3
- python - Python 帮助 MySQL
- node.js - 尝试通过 curl (ubuntu 18.04) 安装 nodejs 时出错
- cpu-registers - 当程序计数器递增时,累加器中的任何值都存储在哪里?
- gradle - Gradle 7 任务 ':distTar' 重复但未设置重复处理策略
- html - 使用 Dash 和 Plotly 在下拉菜单上显示进度条指示器
- python - 获取,TypeError:json 无法序列化类型为 'byte. 通过服务器将表加载到大查询时