Incompatibility Between Flutter Build and Java 21 (Unsupported Class File Major Version 65) #11431
Labels
e1-hours
Effort: < 8 hrs
from.page-issue
Reported in a reader-filed concern
p1-high
Major but not urgent concern: Resolve in months. Update each month.
Page URL
https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide/
Page source
https://github.com/flutter/website/tree/main/src/content/release/breaking-changes/android-java-gradle-migration-guide.md
Describe the problem
encountered a build failure when running flutter build apk using Flutter 3.24.5 on macOS with Java 21. The error suggests an incompatibility between the Gradle version and Java 21:
Unsupported class file major version 65
The issue seems to stem from Gradle not supporting Java 21 yet. Flutter defaults to using Gradle 8.1.1, which only supports Java versions up to 17. This causes builds to fail if Java 21 is installed and configured as the default Java version.
Expected fix
Gradle and Flutter should provide compatibility with Java 21, or a clear error message and documentation should direct users to downgrade Java or upgrade Gradle. It would be helpful if Flutter's flutter doctor command included a compatibility check for Java and Gradle versions.
Additional context
Provide any extra information about your setup:
Flutter Version: 3.24.5 (stable)
Dart Version: 3.5.4
OS: macOS 15.1.1 (arm64)
Java Version: OpenJDK 21.0.3
Gradle Version: 8.1.1 (default Flutter configuration)
The issue was resolved temporarily by downgrading Java to version 17 and upgrading Gradle to version 8.3.
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: