How to fix “Your project’s Gradle version is incompatible with the Java version that Flutter is using for Gradle”

android, linux, marshmallow, smartphone, upgrade, android 6, google, android, android, android, android, android

Incompatible Java/Gradle versions. │

│ Java Version: 21.0.5, Gradle Version: 7.4

This error occurs when there’s a version mismatch between Gradle and Java in your Flutter project. Here’s how to fix it:

  1. First, check your Java version:
java -version

2. Open your project’s android/gradle/wrapper/gradle-wrapper.properties file and update the Gradle version:

To fix the Java/Gradle version incompatibility, let’s update the Gradle version to be compatible with Java 21. Here’s the change: gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

After updating the file:

  1. Run these commands in your project directory:
cd android
gradlew clean
cd ..
flutter clean
flutter pub get

This updates to Gradle 8.5 which is compatible with Java 21. The newer version of Gradle provides better support for recent Java versions.

Welcome to Gradle 8.5!

Here are the highlights of this release:

  • Support for running on Java 21
  • Faster first use with Kotlin DSL
  • Improved error and warning messages

Leave a Comment

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