以下两个问题都来自于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 `文件后重新运行。
- A problem occurred configuring root project 'android'.
- > Could not open proj generic class cache for build file '/xxx/android/build.gradle' (/xx/.gradle/caches/7.5/scripts/akwrc0u19blmw1a04l6gh2lez).
- > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 67
- * 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
复制代码 问题二:Execution failed for task ':gradle:compileGroovy'.
当你发现你本地的jdk版本和gradle的版本对上时,运行的时候还会出现这种报错。
- Execution failed for task ':gradle:compileGroovy'.
- > 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
- * 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 7s
- ┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────┐
- │ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using │
- │ for Gradle. │
- │ │
- │ To fix this issue, consult the migration guide at docs.flutter.dev/go/android-java-gradle-error. │
- └──────────────────────────────────────────────────────────────────────────────────────────────────┘
复制代码 那你就须要执行以下命令来检察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:
|