Repository navigation
[CP-beta] Add java/gradle check when gradle crashes (#189997) - #190364
auto-submit[bot] merged 1 commit into
Conversation
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request introduces a Java and Gradle compatibility check that is triggered upon Gradle build failures to provide clearer troubleshooting steps. It also refactors Gradle version retrieval by extracting getGradleVersionFromFile and adds comprehensive unit tests. The review feedback suggests simplifying the incompatibility error message to improve readability and grammar, along with updating the corresponding test expectations.
| final gradleRangeMax = compat != null && compat.gradleMax != null | ||
| ? ' to ${compat.gradleMax}' | ||
| : ''; | ||
| final gradleRangeCompatSuggestion = compat != null | ||
| ? '${compat.gradleMin}$gradleRangeMax or newer' | ||
| : 'unknown'; | ||
| final gradleRangeInfo = | ||
| 'compatible Gradle versions for Java $javaVersion are $gradleRangeCompatSuggestion'; | ||
| throwToolExit(""" | ||
| Gradle build failed due to Java/Gradle incompatibility. | ||
| The Java version used for the build is $javaVersion, which is incompatible with Gradle $gradleVersion. | ||
| To fix this, you can either: | ||
| 1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties to a version matching the range: $gradleRangeInfo). | ||
| 2. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`."""); |
There was a problem hiding this comment.
The error message is grammatically awkward and redundant (e.g., to a version matching the range: compatible Gradle versions for Java 25.0.4 are 9.1.0 or newer). Additionally, if compat.gradleMax is present, the string would format as 8.4 to 8.5 or newer, which is contradictory.
We can simplify this to be much more concise and natural:
Upgrade your project's Gradle version (typically in gradle-wrapper.properties) to a compatible version (8.4 or newer).
final String gradleRangeCompatSuggestion = compat != null
? (compat.gradleMax != null
? '${compat.gradleMin} to ${compat.gradleMax}'
: '${compat.gradleMin} or newer')
: 'unknown';
throwToolExit("""
Gradle build failed due to Java/Gradle incompatibility.
The Java version used for the build is $javaVersion, which is incompatible with Gradle $gradleVersion.
To fix this, you can either:
1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties) to a compatible version ($gradleRangeCompatSuggestion).
2. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`.""");| throwsToolExit( | ||
| message: | ||
| 'Gradle build failed due to Java/Gradle incompatibility.\n' | ||
| 'The Java version used for the build is 21.0.0, which is incompatible with Gradle 8.0.\n' | ||
| 'To fix this, you can either:\n' | ||
| " 1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties to a version matching the range: compatible Gradle versions for Java 21.0.0 are 8.4 or newer).\n" | ||
| ' 2. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`.' | ||
| ), |
There was a problem hiding this comment.
Update the test expectation to match the simplified and more readable error message.
| throwsToolExit( | |
| message: | |
| 'Gradle build failed due to Java/Gradle incompatibility.\n' | |
| 'The Java version used for the build is 21.0.0, which is incompatible with Gradle 8.0.\n' | |
| 'To fix this, you can either:\n' | |
| " 1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties to a version matching the range: compatible Gradle versions for Java 21.0.0 are 8.4 or newer).\n" | |
| ' 2. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`.' | |
| ), | |
| throwsToolExit( | |
| message: | |
| 'Gradle build failed due to Java/Gradle incompatibility.\n' | |
| 'The Java version used for the build is 21.0.0, which is incompatible with Gradle 8.0.\n' | |
| 'To fix this, you can either:\n' | |
| " 1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties) to a compatible version (8.4 or newer).\n" | |
| ' 2. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`.' | |
| ), |
|
Hi @gmackall since the cherry-pick PR isn't created with the cherry-pick bot, could you review the changes? |
Yeah, the cherry pick failed because it wasn't a clean merge. |
0e98c1f
into
flutter:flutter-3.47-candidate.0
Impacted Users
Anybody attempting to build an Android app with a Gradle incompatible with their JDK. This is now an issue as the RC for Android Studio is JDK 25 which does not work with Gradle 8.14.
Impact Description
The
flutter build apkcommand will crash without a good error message.Workaround
Change your JDK or Gradle version.
Risk
Low
Test Coverage
Good
Validation Steps
flutter config --jdk-dir=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Homeflutter build apkBefore
After
Pre-launch Checklist
///).