React Native 运行 - Android 产生奇怪的错误

Posted

技术标签:

【中文标题】React Native 运行 - Android 产生奇怪的错误【英文标题】:React Native run - Android producing strange error 【发布时间】:2021-06-01 14:23:29 【问题描述】:

我想问一下以下错误。所以一年前我一直在开发一个小型 BLE 应用程序并成功地实现了它。我没有将它推送到 Google Play 商店,而是通过 USB 以某种方式将它安装在 android 上。

但是,现在我需要让它重新启动并运行,但我面临着过多的错误。

PS C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard> npx react-native run-android 
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1302 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Installing the app...

> Configure project :app

Installing unimodules:
 unimodules-core@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\@unimodules\core
 unimodules-react-native-adapter@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\@unimodules\react-native-adapter
 expo-app-loader-provider@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-app-loader-provider
 expo-constants@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-constants
 expo-error-recovery@1.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-error-recovery
 expo-file-system@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-file-system
 expo-font@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-font
 expo-keep-awake@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-keep-awake
 expo-linear-gradient@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-linear-gradient
 expo-location@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-location
 expo-permissions@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-permissions
 expo-sqlite@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-sqlite
 expo-web-browser@8.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\expo-web-browser
 unimodules-barcode-scanner-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-barcode-scanner-interface
 unimodules-camera-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-camera-interface
 unimodules-constants-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-constants-interface
 unimodules-face-detector-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-face-detector-interface
 unimodules-file-system-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-file-system-interface
 unimodules-font-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-font-interface
 unimodules-image-loader-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-image-loader-interface
 unimodules-permissions-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-permissions-interface
 unimodules-sensors-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-sensors-interface
 unimodules-task-manager-interface@5.0.0 from C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard\node_modules\unimodules-task-manager-interface

The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins  ... ' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':expo-error-recovery', ':expo-permissions'

> Task :@react-native-community_async-storage:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
10 actionable tasks: 1 executed, 9 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':@react-native-community_async-storage:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_251 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 31s

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

PS C:\Users\stefanec\Desktop\SOC\i_garden\i_garden\iGard>

【问题讨论】:

【参考方案1】:

您好像没有安装 JDK。

如果您使用的是 Mac,请使用以下命令通过 brew 安装它,或者按照文档了解如何在您的特定机器上安装

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

按照这个guide在windows上安装

请参阅文档https://reactnative.dev/docs/_getting-started-macos-android#installing-dependencies

【讨论】:

幸运儿,非常感谢!我一点也不知道没有 jdk 可能是问题所在,尤其是当我清楚地记得在某个时候安装它时。尽管如此,您的解决方案是 100% 正确的,而且您肯定为我节省了很多时间!请问你是怎么发现的?它没有在任何地方提及。该错误甚至指出了反应库或已弃用的 Gradle,但没有提及缺少 jdk。 太棒了!我很高兴它奏效了。基本上做了一些谷歌搜索并缩小范围。

以上是关于React Native 运行 - Android 产生奇怪的错误的主要内容,如果未能解决你的问题,请参考以下文章

React Native - 运行“npm start”和“react-native run-android”时出错

react-native 未在 Android 更新后运行

在 android 模拟器上运行 react-native

反应原生:未找到 Android 项目。也许先运行 react-native android ?

React Native 运行 Android

从 create react native 弹出后在 android studio 中运行 react native 项目的步骤