我正在为 Android 项目设置 React Native。 我已经安装了所有依赖项并由
npx react-native doctor
检查,这是医生的结果:
Common
✓ Node.js - Required to execute JavaScript code
✓ npm - Required to install NPM dependencies
✓ Metro - Required for bundling the JavaScript code
Android
✓ Adb - Required to verify if the android device is attached correctly
✓ JDK - Required to compile Java code
✓ Android Studio - Required for building and installing your app on Android
✓ ANDROID_HOME - Environment variable that points to your Android SDK installation
✓ Gradlew - Build tool required for Android builds
✓ Android SDK - Required for building and installing your app on Android
Errors: 0
Warnings: 0
现在在终端中我使用
npx react-native run-android
命令来运行我的示例项目,但我收到此错误:
BUILD FAILED in 23s
error Failed to install the app. Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * Where: Settings file 'D:\Projects\AwesomeProject\android\settings.gradle' line: 2 * What went wrong: Error resolving plugin [id: 'com.facebook.react.settings'] > java.io.UncheckedIOException: Could not move temporary workspace (D:\Projects\AwesomeProject\android\.gradle\8.10.2\dependencies-accessors\569c8b261a8a714d7731d5f568e0e5c05babae10-dd285373-4e2a-49c9-8a20-5145657540c5) to immutable location (D:\Projects\AwesomeProject\android\.gradle\8.10.2\dependencies-accessors\569c8b261a8a714d7731d5f568e0e5c05babae10) * 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 23s.
我在 youtube 视频中看到我应该在 android studio 中打开该项目一次,然后这个错误就会得到解决,但我再次遇到同样的错误:
我曾尝试删除 .gradle 目录中的 caches 文件夹,也将 gradle 文件夹访问权限更改为完整。
请任何人帮助我和社区解决这个问题,我会给他买杯咖啡。
12 天后解决了设置 React Native 的冲突,并且社区中没有答案。
运行以下步骤:
npx react-native doctor
cd android
rd /s /q .gradle
npx react-native run-android