The full error usually looks like this, and it appears right after you update Android Studio or install a new JDK:
BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_'
Unsupported class file major version 65
Flutter 3.35 recognises it and adds its own hint: “Your project’s Gradle version is incompatible with the Java version that Flutter is using for Gradle.” Nothing is wrong with your Dart code. Two versions on your machine simply don’t match.
Why it happens
Every Java release writes compiled classes with its own “major version” number. An older Gradle can’t read classes from a newer Java, so it stops while compiling your build scripts.
The usual trigger is an Android Studio update. Flutter uses the JDK that comes bundled with Android Studio unless you tell it otherwise, and recent Android Studio versions bundle Java 21. A project that still runs on Gradle 7.x or early 8.x then fails with major version 65.
Which Java version is your error?
The number in the error tells you the Java version. The last column is the oldest Gradle version that can run on it, from the Gradle compatibility matrix.
| Major version | Java | Min. Gradle |
|---|---|---|
| 61 | Java 17 | 7.3 |
| 65 | Java 21 | 8.5 |
| 66 | Java 22 | 8.8 |
| 67 | Java 23 | 8.10 |
| 68 | Java 24 | 8.14 |
| 69 | Java 25 | 9.1.0 |
Step 1: check what Flutter is using
flutter doctor -v
Under Android toolchain, look for the Java binary at: and Java version lines. That is the JDK Gradle runs on, which is not necessarily the java on your PATH.
Then open android/gradle/wrapper/gradle-wrapper.properties and find your Gradle version:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
Step 2, option A: upgrade Gradle (recommended)
Edit the distributionUrl line directly. Don’t run ./gradlew wrapper for this, because the old Gradle that can’t start is the one that would run it.
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
Gradle 8.12 is what flutter create writes in Flutter 3.35, and it runs on Java 17 and Java 21. Flutter 3.35 also has its own floor: it stops the build below Gradle 8.3 and warns below 8.7.
A Gradle jump often needs a newer Android Gradle Plugin (AGP) as well. Flutter 3.35 fails below AGP 8.1.1 and warns below 8.6.0. New projects use AGP 8.9.1 in android/settings.gradle(.kts):
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.9.1" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}
Paste your Gradle files into the Flutter target API and Gradle checker and it tells you which AGP, Gradle and targetSdk combination to move to.
Step 2, option B: point Flutter at JDK 17
If you can’t upgrade Gradle today, for example because of a release freeze, run Gradle on an older JDK instead:
flutter config --jdk-dir="C:\Program Files\Eclipse Adoptium\jdk-17"
# macOS example: flutter config --jdk-dir=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
Use the path of your own JDK 17 install. Java 17 runs every Gradle from 7.3 up. Treat this as a short-term fix: Flutter warns when Java is below 17, so going lower than 17 just swaps one error for another.
Step 3: clean and rebuild
cd android && ./gradlew --stop && cd ..
flutter clean
flutter pub get
flutter build apk --debug
--stop kills Gradle daemons that are still running on the old JDK. On Windows, use gradlew --stop.
Frequently asked questions
What does "Unsupported class file major version 65" mean in Flutter?
Gradle is running on Java 21 (class file version 65), but your project’s Gradle version is older than 8.5, the first one that supports Java 21. Upgrade Gradle in gradle-wrapper.properties or point Flutter at JDK 17 with flutter config –jdk-dir.
Why did my Flutter build break after updating Android Studio?
Flutter uses the JDK bundled with Android Studio by default. Newer Android Studio versions bundle a newer Java (Java 21), and an older Gradle in your project cannot run on it. Your code did not change; the Java version under Gradle did.
Which Gradle version should a Flutter project use?
With Flutter 3.35, use at least Gradle 8.7 to avoid warnings (8.3 is the hard minimum). New projects get Gradle 8.12 with AGP 8.9.1 and Kotlin 2.1.0. If your JDK is newer than 21, check the Gradle compatibility matrix for the minimum version.
Is it better to downgrade Java or upgrade Gradle?
Upgrade Gradle. Downgrading Java only hides the mismatch until the next Android Studio update, and Google Play’s yearly target API rules eventually force a newer AGP, which needs a newer Gradle anyway.
Stuck on a build or a store release? I fix and maintain Flutter apps, or tell me about your project. More fixes: all Flutter answers.