I'm trying to create a Flutter app, but I'm getting a message about a version conflict between Java and Gradle. The output I received says
The configured version of Java detected may conflict with the Gradle version in your new Flutter app.
[RECOMMENDED] If so, to keep the default Gradle version 8.3, make sure to download a compatible Java version
(Java 17 <= compatible Java version < Java 21).
You may configure this compatible Java version by running:
flutter config --jdk-dir=<JDK_DIRECTORY>
...
Alternatively, to continue using your configured Java version, update the Gradle version specified in the following file to a compatible Gradle version
(compatible Gradle version range: 8.4 - 8.7):
I am not sure how to fix this. Should I change the Java version or update Gradle? What is the best way to solve this issue to make my Flutter app run without errors?
When looking for a "reputable source", see the Compatibility Matrix.
However, there is also one for Android Gradle Plugin and for Android Studio.
Android SDK currently builds with JDK 17, which usually can be found there (when downloaded):
flutter config --jdk-dir=%USERPROFILE%\.jdks\corretto-17.0.13
When Flutter demands: Gradle 8.7, this would be the same as Android Studio Ladybug | 2024.2.1
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
There's also a command to update that:
cd android
gradlew.bat wrapper --gradle-version=8.7
But this permits at most AGP 8.6.0
, because AGP 8.7.2
requires a later Gradle version.
This also means Android build-tools 34.0.0
, which seemingly support API level 35
:
The maximum API level that Android Gradle plugin 8.6 supports is API level 35.