React Native 和 Android Studio:应用无法构建。错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort
Posted
技术标签:
【中文标题】React Native 和 Android Studio:应用无法构建。错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort=8081【英文标题】:React Native and Android Studio: App Failed to build. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 【发布时间】:2021-04-29 19:46:43 【问题描述】:您好,我是 React Native 的新手。我正在尝试使用 android 模拟器在 Windows 操作系统中使用 React Native 运行我的 Android 应用程序。我按照https://reactnative.dev/docs/environment-setup 此处的说明进行操作,但出现以下错误:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
* daemon not running; starting now at tcp:5037
* daemon started successfully
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
* 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 2s
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
这是我的 gradle 属性:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
我的 Java JDK 版本是 15.0.2
我尝试将 gradle 属性更改为较早的版本,但由于最低版本为 6.5 版本,因此无法更改。
有人可以帮帮我吗?
【问题讨论】:
【参考方案1】:命令:
cd ProjectFolder && cd android && ./gradlew clean
如果不成功,尝试以 npx react-native start --reset-cache 启动
如果使用博览会:expo start r -c
【讨论】:
以上是关于React Native 和 Android Studio:应用无法构建。错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort的主要内容,如果未能解决你的问题,请参考以下文章
在react-native中,我如何在ios和android的图像上添加水印
React Native - 运行“npm start”和“react-native run-android”时出错
react-native 配置启动图支持ios和android
我们可以仅将 react-native-firebase 用于 android 和 IOS 其他由 react-native 提供的 api 吗?