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