If you’ve been developing using Flutter to build your MicroSaaS and you’ve just upgraded Android Studio there’s a chance that you will see this annoying build error.
Flutter Error: Unsupported class file major version 65
Launching lib/main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit '/usr/local/Caskroom/flutter/3.22.2/flutter/packages/flutter_tools/gradle/src/main/groovy/app_plugin_loader.groovy' Unsupported class file major version 65
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
You need to get to your project’s folder and run flutter analyze to see what’s going on. flutter doctor won’t be helpful as it tests for different things.
cd /path/to/your-microsaas-app
flutter analyze --suggestions
┌───────────────────────────────────────────────────────────────────┐
│ General Info │
│ [✓] App Name: kolata │
│ [✓] Supported Platforms: android, ios, web, macos, linux, windows │
│ [✓] Is Flutter Package: yes │
│ [✓] Uses Material Design: yes │
│ [✓] Is Plugin: no │
│ [✗] Java/Gradle/Android Gradle Plugin: │
│ Incompatible Java/Gradle versions. │
│ Java Version: 21.0.3, Gradle Version: 7.6.3 │
│ │
│ See the link below for more information: │
│ https://docs.gradle.org/current/userguide/compatibility.html#java │
│ │
└───────────────────────────────────────────────────────────────────┘
So depending on your Java version you need to pick the correct Gradle version
https://docs.gradle.org/current/userguide/compatibility.html#java
you can see all gradle versions here and pick the link that corresponds to your java version – https://services.gradle.org/distributions/
then you need to go to android/gradle/wrapper/ folder within your app’s project and edit gradle-wrapper.properties file.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-3-all.zip
Note it seems the download link value should be escaped i.e. make sure you have a slash before the semi-colon :
distributionUrl=https\://services.gradle.org/distributions/gradle-X-Y-Z-all.zip where X, Y, Z again depend on your Java version. There’s a table see the link a few paragraphs above.
After you’ve updated the Gradle configuration, you should run the command again and should see this output.
cd /path/to/your-microsaas-app
flutter analyze --suggestions
┌───────────────────────────────────────────────────────────────────┐
│ General Info │
│ [✓] App Name: kolata │
│ [✓] Supported Platforms: android, ios, web, macos, linux, windows │
│ [✓] Is Flutter Package: yes │
│ [✓] Uses Material Design: yes │
│ [✓] Is Plugin: no │
│ [✓] Java/Gradle/Android Gradle Plugin: compatible java/gradle/agp │
└───────────────────────────────────────────────────────────────────┘
user@Go359-Online-Store ~/Documents/projects/flutter/car-app-xp1 $
your project compilation may fail again but for a different reason. Some packages may not be compatible with the changes.
You may need to update your packages.
flutter pub get
flutter pub outdated
flutter pub upgrade
flutter pub upgrade --major-versions
aaaaa