【问题标题】:app:compileDebugJavaWithJavac'. > Could not find tools.jar Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`应用程序:compileDebugJavaWithJavac'。 > 找不到 tools.jar 无法启动模拟器。原因:没有找到模拟器作为 `emulator -list-avds` 的输出
【发布时间】:2021-04-14 23:58:27
【问题描述】:

当我在终端中使用这个命令时:

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 react-native gradle android-emulator


    【解决方案1】:

    您可以通过多种方式运行您的应用,

    1. 始终有效 - 从 android studio 打开应用程序。在您的应用中选择Open existing project 并选择android 文件夹以打开项目并在索引完成后从那里运行。
    2. 不确定是否可行且不推荐(可能需要发布版本),但您可以将自动生成的 apk 文件拖到模拟器中进行安装。
    3. 将此行添加到gradle.properties 文件,即android/gradle.propertiesorg.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

    【讨论】:

    • 非常感谢!使用您建议的第一种方法后,它终于起作用了。
    【解决方案2】:

    在我的情况下,这是因为 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
    

    它成功了。

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 2020-10-01
      • 2020-03-12
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      相关资源
      最近更新 更多