skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2.     // TODO: Remove this when flutter Updates
        // ndkVersion: flutter.ndkVersion
        ndkVersion "25.1.8937393"
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        kotlinOptions {
            jvmTarget = '19'
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search