React Native执行run-android仅首次运行成功 后续构建报错解决
Windows 端 React Native CLI 安卓构建运行问题解决记录
前期配置与操作
- 参照官方教程完成Windows端React Native CLI开发环境搭建,日常开发使用VS Code,必要场景的操作可通过Android Studio完成
- 项目初始化执行命令:
npx react-native init AwesomeProject - 安卓端真机调试运行执行命令:
npx react-native run-android
问题表现
- 首次执行安卓运行命令时流程正常,可在连接的真机上正常显示应用启动页
- 后续重复执行相同运行命令时,构建流程中断,无法正常安装应用
问题定位与解决
仅需修改android/gradle/wrapper/gradle-wrapper.properties文件中的单条配置即可解决问题:
- 原配置指向Gradle 6.2版本的安装包地址
- 将配置调整为Gradle 6.3版本的安装包地址后,构建流程恢复正常,对应修改后的配置代码为:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
附:问题触发时的终端报错日志
以下为异常场景下PowerShell终端的完整输出内容:
PS C:\Users\Emre\Documents\Demo\AwesomeProjecttest> npx react-native run-android 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 4 workers... info JS server already running. 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 826ms 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 npm ERR! code 1 npm ERR! path C:\Users\Emre\Documents\Demo\AwesomeProjecttest npm ERR! command failed npm ERR! command C:\Windows\system32\cmd.exe /d /s /c "react-native "run-android"" npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Emre\AppData\Local\npm-cache\_logs\2020-12-01T21_57_28_233Z-debug.log
内容的提问来源于stack exchange,提问作者Stayheuh
相关产品推荐
相关产品推荐

