I’m working on a Flutter project and recently updated to Java 17. Since the update, my build fails with the following error when trying to run assembleDebug:
FAILURE: Build failed with an exception.
- What went wrong:
Could not open cp_settings generic class cache for settings file ‘…/android/settings.gradle’.
BUG! exception in phase ‘semantic analysis’ in source unit ‘BuildScript‘ Unsupported class file major version 65
It seems to be related to Gradle and Java compatibility. I’ve already tried updating the gradle-wrapper.properties to a Gradle version that supports Java 17, but the error persists. Here’s what I’ve done so far:
Updated gradle-wrapper.properties to use Gradle version 7.3.3:
distributionUrl=https://services.gradle.org/distributions/gradle-7.3.3-bin.zip
Ensured Java 17 is installed and set as the default JAVA_HOME on my system.
Flutter doctor output confirms that Flutter is using Java 17.
Despite these steps, the build continues to fail. Here’s the full error output:
BUG! exception in phase ‘semantic analysis’ in source unit ‘BuildScript‘ Unsupported class file major version 65
Steps I’ve Tried:
Updating Gradle to 7.3.3 in gradle-wrapper.properties.
Running flutter clean and rebuilding the project.
Ensuring JAVA_HOME is pointing to the correct Java 17 installation.
Environment:
Flutter version: (specific version)
Java version: 17
Gradle version: 7.3.3 (set in gradle-wrapper.properties)
This is my build.gradle code
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
P.S. All of this started when i updated Android Studio to the Ladybug version
2
Answers
I found the solution to the problem, I followed @Robert advice. All i needed to do was to configure flutter to use my old java 17 directory
after i did that command everything worked.