Ladybug

Android Studio Ladybug: Your project’s Gradle version is incompatible with the Java version that Flutter is using for Gradle.

By

in

I have a Flutter app and I use Android Studio for development. Recently, Android Studio updated to the lastest version Android Studio Ladybug | 2024.2.1 Patch 2. After this update, I didn’t see any problems during the app development. But when it comes to the app build using flutter build appbundle, I got the following error:

[!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle. [...]

It turned out, that the latest update of Android Studio changed the internal JDK version from 17 to 21. And by default, Flutter uses the JDK of Android Studio if you use this one for development.

To fix this, I used the following solution:

Configure Flutter to use JDK 17

This seems to be the solution that worked for my setup.

Step 1: Install JDK 17

Androis Studio already comes with a JDK pre-installed. In case of Ladybug, this is JDK 21 (which currently conflicts with Gradle/Flutter. You can check out the installed SDKs/JDKs by opening “File > Project Structure… > Platform Settings > SDKs”.

In this dialog you can click [ + ] and “Download JDK”:

And select “Version 17” and the “Vendor JetBrains Runtime” – this is the vendor which us already used for the version 21:

This will download JDK 17 an store it at the given path. The JDK home path can now be used for the next step:

Step 2: Configure Flutter to use JDK 17

For this step you can use the following command:

flutter config --jdk-dir <javasdk17-path-dir>

Taking the path from above, the command looks like this:

flutter config --jdk-dir /Users/mathias/Library/Java/JavaVirtualMachines/jbr-17.0.12/Contents/home

To reset the JDK path, simply provide an empty string to the command. This will configure Flutter to use the default JDK of Android Studio:

flutter config --jdk-dir ""

Step 3: Restart Android Studio

Close and reopen Android Studio for the configuration changes to take effect.

Step 4: Update build.gradle

Open the file android/app/build.gradle and ensure that the compatibility versions are set correctly:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = '17'
}

Step 5: Clean and Rebuild the Project

Run the command flutter clean to clear the project cache, then build the project again. You should now be able to build it without issues!

Photo by Sue Thomas on Unsplash.



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *