android 无法启动现有的react native项目,面临gradle问题

qpgpyjmq  于 2024-01-04  发布在  Android
关注(0)|答案(1)|浏览(163)

我试图在我的macOS中运行一个react-native项目。我已经完成了npm install uninstall,clean gradle,但仍然面临同样的问题。
当我运行npm start时,我遇到了下面的问题。

  1. info Opening the app on Android...
  2. info JS server already running.
  3. info Installing the app...
  4. FAILURE: Build failed with an exception.
  5. * What went wrong:
  6. A problem occurred configuring project ':react-native-gradle-plugin'.
  7. > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
  8. > Failed to create parent directory '/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/react-native-gradle-plugin/.gradle' when creating directory '/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/react-native-gradle-plugin/.gradle/buildOutputCleanup'
  9. * Try:
  10. > Run with --stacktrace option to get the stack trace.
  11. > Run with --info or --debug option to get more log output.
  12. > Run with --scan to get full insights.
  13. * Get more help at https://help.gradle.org
  14. BUILD FAILED in 6s
  15. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
  16. FAILURE: Build failed with an exception.
  17. * What went wrong:
  18. A problem occurred configuring project ':react-native-gradle-plugin'.
  19. > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
  20. > Failed to create parent directory '/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/react-native-gradle-plugin/.gradle' when creating directory '/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/react-native-gradle-plugin/.gradle/buildOutputCleanup'
  21. * Try:
  22. > Run with --stacktrace option to get the stack trace.
  23. > Run with --info or --debug option to get more log output.
  24. > Run with --scan to get full insights.
  25. * Get more help at https://help.gradle.org
  26. BUILD FAILED in 6s
  27. at makeError (/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
  28. at /Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
  29. at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  30. at async runOnAllDevices (/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:82:7)
  31. at async Command.handleAction (/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/node_modules/@react-native-community/cli/build/index.js:108:9)
  32. info Run CLI with --verbose flag for more details.

字符串
我不知道在为react-native设置环境时出了什么问题,或者我错过了哪一步。
从npm start运行ios app也会返回类似的结果。

  1. The workspace named "ealpha" does not contain a scheme named "ealpha". The "-list" option can be used to find the names of the schemes in the workspace.


已编辑-
现在我得到了下面的错误。

  1. * What went wrong:
  2. Could not open settings generic class cache for settings file '/Users/ealpha4tech/Downloads/ealpha4-mobile-main 2/android/settings.gradle' (/Users/ealpha4tech/.gradle/caches/7.5.1/scripts/bx94o9il2py3wpbok5l2mnec2).
  3. > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65

a1o7rhls

a1o7rhls1#

解决方案1

1.链接:https://github.com/facebook/react-native/issues/34410
1.链接:https://github.com/facebook/react-native/issues/38034

解决方案2

1.清理Gradle缓存:这有时可以解决Gradle问题。为此,请运行命令:./gradlew clean或gradle clean
1.考虑重建项目。通过这样做,Gradle将被迫从fresh重建项目并下载任何缺少的依赖项。使用以下命令来完成此操作:gradle build或./gradle build

解决方案3

1.您可以使用以下命令删除当前安装的JDK(MacOS):
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk.jdk接下来,从Oracle官方网站下载并启动应用程序。

相关问题