Flutter Android build fails: Java is too new for this Gradle version
Unsupported class file major version 65Short 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
- 1
Unsupported class file major version 65 (Java 21) or 61 (Java 17)The Gradle wrapper is older than the JDK allowsFix - 2
flutter doctor -v shows a Java version that differs from the one you installedFlutter picks a JDK you did not intendFix - 3
The error names a minimum Gradle version required by the pluginThe Android Gradle plugin needs a newer Gradle than the wrapperFix
- 1
What does the error look like?
Unsupported class file major version 65Unsupported class file major version 61Your 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.properties2Fix
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.33Verify
The version command shows the new Gradle and a build starts.
./gradlew --version
cd .. && flutter build apk --debugConfirmed by docs.gradle.org
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_HOME2Fix
Point Flutter at the JDK you want. This applies to all Flutter projects on the machine.
flutter config --jdk-dir=/path/to/jdk-173Verify
doctor now reports that JDK.
flutter doctor -vConfirmed by docs.flutter.dev
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 --debugConfirmed by developer.android.com
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:
- 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 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
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 fixMobile 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_local_notifications crashes on Android with Integer.intValue() on a null object reference
NullPointerException in setSmallIcon
The crash comes from the small icon.
2 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 fix