Solving compatibility issues with Android Studio Ladybug, Java 21, and Flutter

Have you encountered unexpected errors after updating Android Studio to version Ladybug? Discover how to resolve incompatibilities between Flutter and Java 21 with these simple steps and get your projects back on track.

11.10.2024 — Edu Molins — 2 min read
GY00e Uv W4 AI55 Ci 2

If you are a Flutter developer and have updated Android Studio to its latest version (Ladybug), you may have experienced issues when starting your projects. These errors are often related to the installed version of Java/JDK and the Gradle configuration. The main conflict arises from the inclusion of Java version 21 with the Ladybug update, causing incompatibilities with Flutter and requiring an update of the Android Gradle Plugin (AGP), which can become a more complicated process than you expected, especially in already established projects.

Solution: Configuration of Java SDK 17

A simple solution to avoid this conflict is to use an earlier version of Java. Specifically, Java SDK 17, which is compatible with most Flutter projects. Here are the steps to fix it:

  1. Download and Install Java SDK 17: You can download it here. Remember to save the installation path, as you will need it later.

     

  2. Configure Flutter to Use Java 17: Open the terminal and run the following command:

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

     

    This forces Flutter to use Java 17, avoiding conflicts with version 21. Make sure the path points to the /Home folder. For example:

    flutter config --jdk-dir /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home

     

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

     

  4. Update build.gradle: Inside the file android/app/build.gradle, ensure that the compatibility versions are set correctly:

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

     

  5. Clean and Rebuild the Project: Run the command flutter clean to clear the project cache, then run the project again. You should now be able to start it without issues!

Need help?

Updates to tools like Android Studio can bring unexpected challenges, but with simple solutions like this, it's possible to continue working effectively on our Flutter projects. If you have encountered more complications or have projects that need the help of a specialized team, don’t hesitate to contact us. At Liquid Studio, we are experts in Flutter development and can help you overcome any technical challenge you may face.

⚡️ Get the Kit Digital grant to digitize your business. Read more.