skip to Main Content

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


  1. Chosen as BEST ANSWER

    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:

    1. Download Java 17: enter image description here

    2. For "Vendor" choose Jetbrains:

    enter image description here

    1. When downloaded, select Java 17

    enter image description here

    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.


  2. 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:

    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/yourname/Library/Android/sdk
        • Platform android-35, build-tools 34.0.0
        • Java binary at: /opt/homebrew/opt/openjdk@17/bin/java
        • Java version OpenJDK Runtime Environment Homebrew (build 21.0.3+-79915917-b509.11) <-- Current Java version
        • All Android licenses accepted.
    

    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:

      brew install openjdk@17
      
    • Set Java 17 as the active Java version:

      echo 'export JAVA_HOME=$(brew --prefix openjdk@17)' >> ~/.zshrc
      source ~/.zshrc
      
    • Verify the installation:

      echo $JAVA_HOME
      
    • The output should be something like:

      /opt/homebrew/opt/openjdk@17
      
    • Set the JDK directory for Flutter:

      flutter config --jdk-dir=$JAVA_HOME
      
    • Confirm the Java version:

      java -version
      

      The output should show:

      openjdk version "17.0.12" 2024-07-16
      

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search