我正在尝试在 Android 中运行我的 React Native Expo 项目,它向我显示了这个错误
macbookpro@macbooks-MacBook-Pro appv2 % npx expo run:android --device
✔ Select a device/emulator › Pixel_6_Pro (device)
› Using --device Pixel_6_Pro
› Building app...
Configuration on demand is an incubating feature.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'appv2'.
> Could not open cp_proj generic class cache for build file '/Users/macbookpro/Documents/GitHub/appv2/android/build.gradle' (/Users/macbookpro/.gradle/caches/8.3/scripts/f4c1320ij7nr1ls7oyh73uai8).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66
* 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 6s
Error: /Users/macbookpro/Documents/GitHub/appv2/android/gradlew exited with non-zero code: 1
Error: /Users/macbookpro/Documents/GitHub/appv2/android/gradlew exited with non-zero code: 1
at ChildProcess.completionListener (/Users/macbookpro/Documents/GitHub/appv2/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
at Object.onceWrapper (node:events:629:26)
at ChildProcess.emit (node:events:514:28)
at maybeClose (node:internal/child_process:1091:16)
at ChildProcess._handle.onexit (node:internal/child_process:302:5)
...
at Object.spawnAsync [as default] (/Users/macbookpro/Documents/GitHub/appv2/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
at spawnGradleAsync (/Users/macbookpro/Documents/GitHub/appv2/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
at Object.assembleAsync (/Users/macbookpro/Documents/GitHub/appv2/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
at runAndroidAsync (/Users/macbookpro/Documents/GitHub/appv2/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24)
尝试以下操作: rm -rf node_modules && npm 缓存清理 --force && npm install && watchman watch-del-all && rm -rf $TMPDIR/haste-map-* && rm -rf $TMPDIR/metro-cache
然后,重新开始运行。
这将删除node_modules,清理npm缓存,重新安装node_modules,删除当前运行的监视和metro缓存。