我正在尝试使用最新版本(0.75.2)创建一个反应本机应用程序。我用
npx @react-native-community/cli init newapp
创建了该项目。然后我使用 yarn start
命令启动项目。然后,当我输入 yarn android
时,它会下载 gradle 属性中写入的 gradle 8.8 (distributionUrl=https://services.gradle.org/distributions/gradle-8.8-all.zip)。然后错误就来了。
FAILURE: Build failed with an exception.
* Where:
Settings file 'C:\Users\JOHN\Desktop\react\newapp\android\settings.gradle' line: 2
* What went wrong:
Error resolving plugin [id: 'com.facebook.react.settings']
> java.io.UncheckedIOException: Could not move temporary workspace (C:\Users\JOHN\Desktop\react\newapp\android\.gradle\8.8\dependencies-accessors\569c8b261a8a714d7731d5f568e0e5c05babae10-d380c3b5-5c8f-4497-a8a6-a9f1675d5c36) to immutable location (C:\Users\JOHN\Desktop\react\newapp\android\.gradle\8.8\dependencies-accessors\569c8b261a8a714d7731d5f568e0e5c05babae10)
我尝试了很多次,我跑了
npx react-native doctor
但没有运气和结果:
Common
✓ Node.js - Required to execute JavaScript code
✓ yarn - 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
- Versions found: N/A
- Version supported: 34.0.0
注意:我使用的是react-native 0.69版本,没有任何错误。
react-native 信息输出:
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
Memory: 16.19 GB / 31.75 GB
Binaries:
Node:
version: 20.10.0
path: C:\Program Files\nodejs\node.EXE
Yarn:
version: 3.6.4
path: ~\AppData\Roaming\npm\yarn.CMD
npm:
version: 10.2.3
path: C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
Windows SDK: Not Found
IDEs:
Android Studio: AI-231.9392.1.2311.11255304
Visual Studio: Not Found
Languages:
Java: 17.0.9
Ruby: Not Found
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.75.2
wanted: 0.75.2
react-native-windows: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
Gradle 版本输出为:
------------------------------------------------------------
Gradle 8.8
------------------------------------------------------------
Build time: 2024-05-31 21:46:56 UTC
Revision: 4bd1b3d3fc3f31db5a26eecb416a165b8cc36082
Kotlin: 1.9.22
Groovy: 3.0.21
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.9 (Microsoft 17.0.9+8-LTS)
OS: Windows 10 10.0 amd64
编辑:我按照本论坛答案的建议将 gradle 降级到 8.5,但还是没有运气。 gradlew clean 也无法处理相同的错误。
也许尝试一下并安装 Android SDK 34.0.0,因为这是您的设置中缺少的一部分!并确保将其添加到您的 $PATH 中。