Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter Android build fails: Java is too new for this Gradle version

ErrorUnsupported class file major version 65

Short answer

Gradle only runs on Java versions it knows. Java 17 needs Gradle 7.3 or newer and Java 21 needs Gradle 8.5 or newer. So either raise the Gradle version in the android folder, or tell Flutter to use a JDK the current Gradle supports. Check the AGP's minimum Gradle too.

  • Applies to Flutter 3.35, Gradle 8.5 to 9.x, JDK 17 and 21, Android Gradle plugin 8.x and 9.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print which Java Flutter uses and which Gradle the project wraps. The two must match the table in the Gradle docs.

    flutter doctor -v | grep -i java
    cd android && ./gradlew --version
  2. 2Match what you see, then jump to its fix

    1. 1Unsupported class file major version 65 (Java 21) or 61 (Java 17)The Gradle wrapper is older than the JDK allowsFix
    2. 2flutter doctor -v shows a Java version that differs from the one you installedFlutter picks a JDK you did not intendFix
    3. 3The error names a minimum Gradle version required by the pluginThe Android Gradle plugin needs a newer Gradle than the wrapperFix

What does the error look like?

  • Unsupported class file major version 65
  • Unsupported class file major version 61
  • Your build is currently configured to use incompatible Java and Gradle versions

Cause 1 of 3

The Gradle wrapper is older than the JDK allows

1Check

Gradle runs on Java 17 from 7.3 and on Java 21 from 8.5. Read the wrapper version in the properties file.

grep distributionUrl android/gradle/wrapper/gradle-wrapper.properties

2Fix

Upgrade the wrapper from the android folder. Run the task twice, as the Gradle docs describe, so the scripts and jar update as well.

cd android
./gradlew :wrapper --gradle-version 8.14.3
./gradlew :wrapper --gradle-version 8.14.3

3Verify

The version command shows the new Gradle and a build starts.

./gradlew --version
cd .. && flutter build apk --debug

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

Flutter picks a JDK you did not intend

1Check

Flutter uses the Java bundled with Android Studio if present; without it, it uses JAVA_HOME, then java on PATH.

flutter doctor -v
echo $JAVA_HOME

2Fix

Point Flutter at the JDK you want. This applies to all Flutter projects on the machine.

flutter config --jdk-dir=/path/to/jdk-17

3Verify

doctor now reports that JDK.

flutter doctor -v

Confirmed by docs.flutter.dev

Did this fix it?

Cause 3 of 3

The Android Gradle plugin needs a newer Gradle than the wrapper

1Check

Each AGP release lists a minimum Gradle. For example AGP 9.5 needs Gradle 9.6.0 and JDK 17.

grep -rn "com.android.application" android/settings.gradle* android/build.gradle*

2Fix

Raise the Gradle wrapper to at least that minimum, or lower the AGP version. For Flutter projects, flutter analyze --suggestions names a Gradle version to use.

flutter analyze --suggestions
cd android && ./gradlew :wrapper --gradle-version <suggested-version>

3Verify

A debug build completes.

flutter build apk --debug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Commit the Gradle wrapper files so every machine builds with the same Gradle.
  • When you upgrade the JDK, check the Gradle compatibility table before building.
  • Run flutter doctor -v after changing JAVA_HOME or installing Android Studio.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Flutter Android: Failed to load FirebaseOptions from resource

Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.

On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.

4 causes, each with a fix

Mobile apps

Flutter's Android build stops: JAVA_HOME is not set

ERROR: JAVA_HOME is set to an invalid directory

The Gradle wrapper script needs a Java runtime and looks in two places: the JAVA_HOME variable, then a java command on PATH.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.