Skip to content

[CP-beta] Add java/gradle check when gradle crashes (#189997) - #190364

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
mboetger:cp-java-gradle-check
Aug 4, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.47-candidate.0from
mboetger:cp-java-gradle-check

Conversation

@mboetger

Copy link
Copy Markdown
Contributor

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 apk command will crash without a good error message.

Workaround

Change your JDK or Gradle version.

Risk

Low

Test Coverage

Good

Validation Steps

  1. Set the JDK: flutter config --jdk-dir=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home
  2. Build the APK: flutter build apk
  3. Verify the error message (seen below)

Before

❯ flutter config --jdk-dir=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home
Setting "jdk-dir" value to "/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home".

You may need to restart any open editors for them to read new settings.
❯ flutter build apk
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader in an unnamed module (file:/Users/boetger/.gradle/wrapper/dists/gradle-8.14-all/c2qonpi39x1mddn7hk5gh9iqj/gradle-8.14/lib/native-platform-0.22-milestone-28.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled


FAILURE: Build failed with an exception.

* What went wrong:
25.0.4

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 321ms

After

❯ flutter config --jdk-dir=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home
Setting "jdk-dir" value to "/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home".
You may need to restart any open editors for them to read new settings.
❯ flutter build apk
Gradle build failed due to Java/Gradle incompatibility.
The Java version used for the build is 25.0.4, which is incompatible with Gradle 8.14.
To fix this, you can either:
  1. Upgrade your project's Gradle version (typically in gradle-wrapper.properties to a version matching the range: compatible Gradle versions for Java 25.0.4 are 9.1.0
  to newer).
  5. Use a different Java version for Flutter by running `flutter config --jdk-dir=<path>`.
Alternatively, you can bypass this check using "--android-skip-build-dependency-validation".

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@mboetger
mboetger requested a review from a team as a code owner July 31, 2026 18:38
@mboetger
mboetger requested review from gmackall and removed request for a team July 31, 2026 18:38
@mboetger mboetger added the cp: review Cherry-picks in the review queue label Jul 31, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 31, 2026
@flutter-dashboard

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Jul 31, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +466 to +479
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>`.""");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>`.""");

Comment on lines +3147 to +3154
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>`.'
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the test expectation to match the simplified and more readable error message.

Suggested change
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>`.'
),

@LongCatIsLooong

Copy link
Copy Markdown
Contributor

Hi @gmackall since the cherry-pick PR isn't created with the cherry-pick bot, could you review the changes?

@mboetger

mboetger commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

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.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 4, 2026
@auto-submit
auto-submit Bot merged commit 0e98c1f into flutter:flutter-3.47-candidate.0 Aug 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants