After upgrading to Android Studio Ladybug I get the following error message:
Your build is currently configured to use incompatible Java 21.0.3 and Gradle 8.0. Cannot sync the project.
We recommend upgrading to Gradle version 8.9.
The minimum compatible Gradle version is 8.5.
The maximum compatible Gradle JVM version is 19.
Possible solutions:
- Upgrade to Gradle 8.9 and re-sync
- Upgrade to Gradle 8.5 and re-sync
I don’t want to upgrade Gradle now. What is the simplest solution to build my project?
2
Answers
If you don't want to upgrade Gradle yet, the simplest and fatest solution is to downgrade the Java SDK by downloading an older version. Here is how to do it:
Download Java 17:
For "Vendor" choose Jetbrains:
N.B. If after downgrading to Java 17 you still cannot build and you see an error like
module jdk.compiler does not export com.sun.tools.javac.main to unnamed module
, you should restart your machine.To resolve the issue you’re facing with Android Studio Ladybug and the incompatible Java 21.0.3 version, it’s likely caused by Android Studio upgrading to Java 20+, while your Flutter project might need Java 17.
Here’s what you can do:
1. Check Your Java Version with Flutter Doctor
Run the
flutter doctor -v
command to check the Java version being used by your Flutter setup. Look for the section that shows the Java version, like this:If the Java version shows 21 or higher, you’ll need to downgrade to Java 17, which is compatible with your current Gradle setup.
2. Downgrade Java to Version 17
If you are using macOS with Homebrew, follow these steps:
Install Java 17 via Homebrew:
Set Java 17 as the active Java version:
Verify the installation:
The output should be something like:
Set the JDK directory for Flutter:
Confirm the Java version:
The output should show:
3. Re-sync Your Project
After downgrading to Java 17, re-sync your project in Android Studio, and it should work without issues.
Why Java 17?
Flutter currently requires Java 17 for compatibility with certain Gradle versions. If you upgrade to Java 21, it might cause syncing errors with older Gradle versions like 8.0 or 8.5. By ensuring you’re using Java 17, you maintain compatibility with your current setup, avoiding the need to upgrade Gradle.