Skip to content

Flutter Android build errorWhy does my Flutter build say “Unsupported class file major version”?

The Android build stopped with a long Gradle stack trace and “Unsupported class file major version 61” (or 65) near the top. The cause is the Java version, not your Dart code. Here’s how to match Java, Gradle and the Android Gradle Plugin again, or hand it over at a fixed price.

Short answer

The Java version building your app is newer than your project’s Gradle version can handle. Flutter builds with the Java bundled with Android Studio, so an Android Studio update can trigger it. Run flutter analyze --suggestions to see which of AGP, Java and Gradle don’t fit together, then update the Gradle wrapper to the suggested version, or set the Java version Flutter uses with flutter config --jdk-dir.

What changed, and the fix

  1. 01

    Java got newer, Gradle didn’t

    “This is an indication that your Java version is newer than the version of Gradle you are running can handle.” Flutter, Android Java Gradle migration guide

    The error means the Java running your build is newer than your Gradle can handle. Flutter’s guide notes the versions of AGP, Java and Gradle depend on each other in ways that aren’t obvious, so update them together.

  2. 02

    Android Studio updated its bundled Java

    “Flutter uses the version of Java bundled with Android Studio to build Android apps.” Flutter, Android Java Gradle migration guide

    Flutter uses the Java that ships with Android Studio, so updating Android Studio can change the Java version under your build without any change to the project. Run flutter doctor to see which Java is in use.

    flutter doctor
  3. 03

    Fix it: update Gradle to the suggested version

    “Run flutter analyze --suggestions to see if your AGP, Java, and Gradle versions are compatible.” Flutter, Android Java Gradle migration guide

    Flutter’s guide calls Android Studio’s AGP Upgrade Assistant the easiest way to resolve this: select your top-level build.gradle, then Tools > AGP Upgrade Assistant. From the command line, ask Flutter which versions fit, then update Gradle to the version it suggests (or newer) from your project’s Android directory.

    flutter analyze --suggestions
    cd android && ./gradlew wrapper --gradle-version=SOMEGRADLEVERSION
  4. 04

    Or: set the Java version Flutter uses

    “To set the version of Java that all flutter projects use run flutter config --jdk-dir=SOMEJAVAPATH” Flutter, Android Java Gradle migration guide

    Flutter’s guide also shows how to set the Java version all your Flutter projects use, so you can pick one your Gradle can run with. On a Mac, /usr/libexec/java_home -V lists the Java versions installed.

    flutter config --jdk-dir=/path/to/your/jdk

Checked against the vendor’s docs on : Flutter docs: Android Java Gradle migration guide.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Flutter Android build fails after AGP 9 · Flutter “applying Gradle plugin imperatively” error · Flutter pod install failed

Questions

More on this error

Does this affect people who don’t use Android Studio?

Yes. Flutter’s guide says it can happen to people who don’t download Java and the Android SDK through Android Studio too, for example after upgrading Java yourself without upgrading Gradle.

I have several Android apps. Do I fix each one?

Yes. Flutter’s guide says to repeat the fix for each affected Android app.

Which Gradle version should I use?

Use the version flutter analyze --suggestions gives you. Flutter’s guide says you can use a newer version than the one suggested, and notes that its workarounds may go out of date over time.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.