Flutter Android build fails with Unsupported class file major version
Unsupported class file major version 61Short 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
- 1
Unsupported 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
flutter 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
Android Gradle plugin requires Java 17 to run. You are currently using Java 11.The JDK is older than the Android Gradle plugin needsFix
- 1
What does the error look like?
Unsupported class file major version 61Unsupported class file major version 65BUG! 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.properties2Fix
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.03Verify
The build script compiles and the debug build finishes.
flutter build apk --debugConfirmed by docs.gradle.org
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_HOME2Fix
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/home3Verify
flutter doctor -v now shows that path, and the build runs.
flutter doctor -v | grep -i java
flutter build apk --debugConfirmed by docs.flutter.dev
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 --version2Fix
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/home3Verify
The gradlew output lists the JVM you set, and the plugin error is gone.
cd android && ./gradlew --versionConfirmed by developer.android.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile 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 fixMobile apps
flutter run hangs for minutes on Running Gradle task 'assembleDebug'
Downloading https://services.gradle.org/distributions/gradle-8.14-all.zip
That line only says Gradle started; the wait is inside Gradle.
3 causes, each with a fixMobile apps
flutter doctor cannot find the Java that comes with Android Studio
Unable to find bundled Java version.
Flutter looks for the Java inside Android Studio first, then JAVA_HOME, then any java on PATH.
3 causes, each with a fixMobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fixMobile 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