如何解决应用程序:compileDebugJavaWithJavac' > 找不到 tools.jar 无法启动模拟器原因:没有找到模拟器作为 `emulator -list-avds` 的输出
当我在终端中使用这个命令时:
PS C:\web dev\practice-projects\react-native\myproject> react-native run-android --no-jetifier
我得到了整个错误:
info JS server already running.
'adb' is not recognized as an internal or external command,operable program or batch file.
info Launching emulator...
error
Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...
Starting a Gradle Daemon,1 stopped Daemon could not be reused,use --status for details
> Task :app:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build,making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warning
14 actionable tasks: 2 executed,12 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_271 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
BUILD FAILED in 39s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
我的模拟器没有启动,我尝试了多种修复。我刚开始使用 react-native,不了解类似问题的警告或答案。请帮忙。
解决方法
有几种方法可以运行您的应用,
- 始终有效 - 从 android studio 打开应用程序。在您的应用中选择
Open existing project
并选择android
文件夹以打开项目并在索引完成后从那里运行。 - 不确定是否可行且不推荐(可能需要发布版本),但您可以将自动生成的 apk 文件拖到模拟器中进行安装。
- 将此行添加到
gradle.properties
文件,即android/gradle.properties
。org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
。如果需要,替换 jdk 版本名称或目录。
Mac 的注意事项 - 这不是您用户目录中的 library folder
,因此在您的主驱动器位置搜索它们 - 应该类似于 machintosh hd
对于 Windows - 只需替换 org.gradle.java.home=
之后的路径。应该类似于 C:\\Program Files\\Java\\jdk1.8.0_144
就我而言,这是因为 JAVA_HOME 路径找不到它。
-
关闭所有终端并打开一个新的
-
在您的 Mac 上找到这样的目录: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
-
可能会改变的是版本,但是一旦你有了它,它就会在那个版本中运行 小路: 导出 JAVA_HOME = / 库 / Java / JavaVirtualMachines / jdk1.8.0_91.jdk / 目录 / 首页
在我的情况下,我在 React NATIVE 项目的根运行此命令:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
它奏效了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。