Maaz Zindani

Loading the index…

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

Flutter Android build fails with Unsupported class file major version

ErrorUnsupported class file major version 61

Short answer

The number is the Java version that tried to read a file: 61 is Java 17, 65 is Java 21. The error means the Java running Gradle is newer than that Gradle can handle, or the JDK Flutter picked is not the one you expect. Upgrade the Gradle wrapper, or point Flutter at a JDK that fits.

  • Applies to Flutter 3.3x stable, Gradle 8.x and 9.x, Android Gradle Plugin 8.x and 9.x, JDK 17 and 21, macOS 26, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Flutter which Java it uses, then ask the project's own Gradle wrapper which Gradle and JVM it runs on. The two numbers must fit together.

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

    1. 1Unsupported class file major version 61 (or 65) printed while Gradle compiles its own build scriptThe Gradle wrapper is older than the JDK that runs itFix
    2. 2flutter doctor -v lists a Java path you did not expect, such as an old Homebrew or system JDKFlutter is using a different JDK than the one you meantFix
    3. 3Android Gradle plugin requires Java 17 to run. You are currently using Java 11.The JDK is older than the Android Gradle plugin needsFix

What does the error look like?

  • Unsupported class file major version 61
  • Unsupported class file major version 65
  • BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_'
  • Android Gradle plugin requires Java 17 to run. You are currently using Java 11.

Cause 1 of 3

The Gradle wrapper is older than the JDK that runs it

1Check

Read the Gradle version in the wrapper file and compare it with Gradle's own table of which Java versions each release can run on. Java 17 needs Gradle 7.3 or newer, Java 21 needs 8.5 or newer, Java 24 needs 8.14 or newer.

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

2Fix

Raise the wrapper to a Gradle version that supports your JDK and that your Android Gradle plugin accepts (AGP 9.5 needs Gradle 9.6.0 or newer). Flutter's own check suggests a version if you are unsure.

flutter analyze --suggestions
cd android
./gradlew wrapper --gradle-version=9.6.0

3Verify

The build script compiles and the debug build finishes.

flutter build apk --debug

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

Flutter is using a different JDK than the one you meant

1Check

Flutter uses the Java bundled with Android Studio first. Without Android Studio it reads JAVA_HOME, and without that it takes the first java on PATH. flutter doctor -v prints the one it chose.

flutter doctor -v | grep -i java
echo $JAVA_HOME

2Fix

Tell Flutter which JDK every project should use. Pick a JDK your Gradle and AGP versions both support, for example 17.

/usr/libexec/java_home -V
flutter config --jdk-dir=/path/to/your/jdk-17/home

3Verify

flutter doctor -v now shows that path, and the build runs.

flutter doctor -v | grep -i java
flutter build apk --debug

Confirmed by docs.flutter.dev

Did this fix it?

Cause 3 of 3

The JDK is older than the Android Gradle plugin needs

1Check

AGP 8.x and newer need JDK 17 or later to run. In a terminal Gradle uses JAVA_HOME, or the java on PATH if that is unset. Inside Android Studio it uses the Gradle JDK from Settings.

java -version
cd android && ./gradlew --version

2Fix

Install JDK 17 or newer and make the terminal use it. As a project-only override, set org.gradle.java.home in android/gradle.properties.

# android/gradle.properties
org.gradle.java.home=/path/to/your/jdk-17/home

3Verify

The gradlew output lists the JVM you set, and the plugin error is gone.

cd android && ./gradlew --version

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Change the Gradle wrapper, the Android Gradle plugin and the JDK together, using the version tables from Gradle and Google as the guide.
  • Set flutter config --jdk-dir once so every project uses the same Java.
  • Commit android/gradle/wrapper/gradle-wrapper.properties so everyone and CI build with the same Gradle.
  • Run flutter doctor -v after every Android Studio or JDK update.

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'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

Mobile apps

A phone is plugged in over USB but Android Studio and adb do not list it

adb devices prints List of devices attached with nothing below it

adb lists a phone only when four things hold: USB debugging is on, you accepted the computer's RSA key on the phone, the computer has a driver or udev rule for the device, and the cable carries data to a running adb server.

6 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.