Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Build Fails with "Unsupported class file major version 65" After Updating to Java 17

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

like image 237
Convert.ToInt32 Avatar asked Dec 06 '25 18:12

Convert.ToInt32


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

flutter config --jdk-dir <path-to-java-sdk-17-home-directory>

after I did that command everything worked.

like image 74
Convert.ToInt32 Avatar answered Dec 08 '25 07:12

Convert.ToInt32


For me, instead of trying to install or look for older gradle which doesn't exist on my machine. I look for the gradle definition on my newly created Flutter project and copy back to my older project.

Create a new flutter project and look for distributionUrl in /android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip

Copy and paste back to your older project's

like image 31
VitSoonYoung Avatar answered Dec 08 '25 07:12

VitSoonYoung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!