Fix “Unsupported Class File Major Version 65” in Flutter Android Builds (Java 21 Issue)

When building a Flutter app for Android, you might run into this cryptic error during the Gradle build phase:

Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit ...
  Unsupported class file major version 65

If you’re seeing this, you’re not alone, and the fix is straightforward once you understand the cause.


What’s Going On?

The error:

Unsupported class file major version 65

means that Gradle or one of its plugins (like Groovy) is trying to read a .class file compiled with a Java version it doesn’t support.

Specifically, major version 65 = Java 21.

Java VersionClass File Major Version
Java 852
Java 1155
Java 1761
Java 2165, This is the one causing the error

But wait, what does “your current Java version” mean in Flutter?

Flutter’s Android toolchain follows this priority order when selecting which Java executable to use:

  • Android Studio’s bundled JDK (if installed)
  • The JDK pointed to by your JAVA_HOME environment variable
  • The java binary found on your system PATH

So even if you’ve correctly set JAVA_HOME, Flutter might still use a different JDK — especially the one bundled with Android Studio.


Solution

If your team is intentionally using Java 21, you’ll need to upgrade your Gradle stack (Android Gradle Plugin + Gradle wrapper) to support it.

But if you’re using Java 18 and you’ve already set JAVA_HOME, Flutter still picks up Java 21 (e.g., from Android Studio), the simplest solution is to explicitly tell Flutter which JDK to use.

Point Flutter directly to your installed JDK. In my case:

fvm flutter config --jdk-dir="C:\Program Files\Eclipse Adoptium\jdk-18.0.2.101-hotspot"

Then verify:

fvm flutter doctor --verbose

You should see:

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\cdlee\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Eclipse Adoptium\jdk-18.0.2.101-hotspot\bin\java
    • Java version OpenJDK Runtime Environment Temurin-18.0.2.1+1 (build 18.0.2.1+1)
    • All Android licenses accepted.

Finally, rebuild your project:

fvm flutter clean
fvm flutter build apk --release

This lets you use your local Java 18 installation for Flutter without changing any project files, ideal for individual dev machines or CI runners.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top