Android Studio中configuring root project ‘android‘和failed for task ...

河曲智叟  金牌会员 | 2025-2-19 07:51:12 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 880|帖子 880|积分 2640

以下两个问题都来自于java的sdk和gradle版本兼容问题。
我们先来参考一下gradle提供的版本兼容对照表Compatibility Matrix:
Java versionSupport for toolchainsSupport for running Gradle 8
  N/A
  2.0
  9
  N/A
  4.3
  10
  N/A
  4.7
  11
  N/A
  5.0
  12
  N/A
  5.4
  13
  N/A
  6.0
  14
  N/A
  6.3
  15
  6.7
  6.7
  16
  7.0
  7.0
  17
  7.3
  7.3
  18
  7.5
  7.5
  19
  7.6
  7.6
  20
  8.1
  8.3
  21
  8.4
  8.5
  22
  8.7
  8.8
  23
  8.10
  8.10
  24
  N/A
  N/A
  问题一:A problem occurred configuring root project 'android'.
以此类推来对应你的flutter项目下`./android/gradle/wrapper/gradle-wrapper.properties`文件上`distributionUrl=`gradle使用版本,来安装对应的jdk大概修改gradle的版本。
   修改后删除`./android/gradle/wrapper/gradle-wrapper.jar `文件后重新运行。
  1. A problem occurred configuring root project 'android'.
  2. > Could not open proj generic class cache for build file '/xxx/android/build.gradle' (/xx/.gradle/caches/7.5/scripts/akwrc0u19blmw1a04l6gh2lez).
  3.    > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 67
  4. * Try:
  5. > Run with --stacktrace option to get the stack trace.
  6. > Run with --info or --debug option to get more log output.
  7. > Run with --scan to get full insights.
  8. * Get more help at https://help.gradle.org
复制代码
问题二:Execution failed for task ':gradle:compileGroovy'.
当你发现你本地的jdk版本和gradle的版本对上时,运行的时候还会出现这种报错。
  1. Execution failed for task ':gradle:compileGroovy'.
  2. > BUG! exception in phase 'semantic analysis' in source unit '/xxxx/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' Unsupported class file major version 65
  3. * Try:
  4. > Run with --stacktrace option to get the stack trace.
  5. > Run with --info or --debug option to get more log output.
  6. > Run with --scan to get full insights.
  7. * Get more help at https://help.gradle.org
  8. BUILD FAILED in 7s
  9. ┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────┐
  10. │ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using    │
  11. │ for Gradle.                                                                                      │
  12. │                                                                                                  │
  13. │ To fix this issue, consult the migration guide at docs.flutter.dev/go/android-java-gradle-error. │
  14. └──────────────────────────────────────────────────────────────────────────────────────────────────┘
复制代码
那你就须要执行以下命令来检察flutter使用的是那个版本的jdk:
   flutter doctor -v
  在Android Studio这一行中,检察
   [✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
     
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

河曲智叟

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表