Upgraded to Android studio Android studio 2024.2.1. Even did a fresh install.
Made a new Flutter project. When I run it, I get this error.
Launching libmain.dart on Pixel 8 in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit 'C:UsersRokFlutter SDKflutterpackagesflutter_toolsgradlesrcmaingroovyapp_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
BUILD FAILED in 5s
┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using │
│ for Gradle. │
│ │
│ If you recently upgraded Android Studio, consult the migration guide at │
│ https://flutter.dev/to/to/java-gradle-incompatibility. │
│ │
│ Otherwise, to fix this issue, first, check the Java version used by Flutter by running `flutter │
│ doctor --verbose`. │
│ │
│ Then, update the Gradle version specified in │
│ C:UsersRokFlutterProjectsTesttest20241009androidgradlewrappergradle-wrapper.properties │
│ to be compatible with that Java version. See the link below for more information on compatible │
│ Java/Gradle versions: │
│ https://docs.gradle.org/current/userguide/compatibility.html#java │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1
Can run Android Java project without problems.
Tried a full uninstall and reinstall of Android Studio.
2
Answers
This error occurs due to an incompatibility between the version of Java you’re using and the Gradle version specified in your Flutter project.
Solution:
Check the Java version Flutter is using
Run the following command to verify the Java version being used by Flutter:
Look for the Java version in the output.
Update the Gradle version
Based on the Java version from the previous step, you need to update your gradle-wrapper.properties file. This file is located at:
Modify the distributionUrl to a compatible Gradle version. For example:
Replace with the correct version based on your Java version. You can refer to the compatibility table here.
Sync and rebuild the project
Once you’ve updated the Gradle version, sync your project in Android Studio to apply the changes. Then, run the following commands to clean and rebuild the project:
These steps should resolve the issue.
Additional Resources:
Gradle issues
The same happened to me today, after installing Android Studio Ladybug 2024.2.1.
As far as I understand, this is related to the new Java 21 version installed by AS.
Solution
C:project_pathandroidgradlewrappergradle-wrapper.properties
pubspec.yaml
First build time may take longer (about 30 minutes for my project), so be patient.
Sometimes you may need to manually delete old packages from cache c:Users<username>AppDataLocalPubCachehostedpub.dev
You are done! Easy peasy!