Skip to content

Add javaHeapSpaceHandler to handle Gradle build failures due to Java …#185127

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
mozammal-hossain:fix/gradle-error-message-163801
Jul 7, 2026
Merged

Add javaHeapSpaceHandler to handle Gradle build failures due to Java …#185127
auto-submit[bot] merged 4 commits into
flutter:masterfrom
mozammal-hossain:fix/gradle-error-message-163801

Conversation

@mozammal-hossain

@mozammal-hossain mozammal-hossain commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Adds a new Gradle error handler in flutter_tools for Java heap space failures (java.lang.OutOfMemoryError: Java heap space).
When detected, Flutter now shows a clear Flutter Fix message with actionable guidance to increase org.gradle.jvmargs in android/gradle.properties, instead of only surfacing raw Gradle output.

Fixes #163801.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@mozammal-hossain
mozammal-hossain requested a review from a team as a code owner April 16, 2026 02:46
@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 Apr 16, 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 new error handler, javaHeapSpaceHandler, to detect Java heap space exhaustion during Gradle builds and suggest increasing memory limits in gradle.properties. Feedback suggests refining the user instructions to avoid overwriting existing JVM arguments when updating the configuration file.

Comment thread packages/flutter_tools/lib/src/android/gradle_errors.dart Outdated
@reidbaker
reidbaker requested review from mboetger and reidbaker April 21, 2026 18:01
Comment on lines +358 to +367
'If org.gradle.jvmargs is already set, append these flags to the existing value '
'(keep your other JVM arguments, such as file encoding):\n'
'-Xmx4G -XX:MaxMetaspaceSize=2G\n'
'If org.gradle.jvmargs is not set, add a line such as:\n'
'org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G',
);
globals.printBox(
'${globals.logger.terminal.warningMark} The Gradle build ran out of Java heap space.\n'
'$textInBold\n\n'
'If this error continues, increase the -Xmx and -XX:MaxMetaspaceSize values based on your machine resources.',

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.

Since we don't know how much memory will be needed, instead of giving values just point them at the documentation: https://docs.gradle.org/current/userguide/config_gradle.html#sec:configuring_jvm_memory

Suggestion: "Adjust the maximum java heap allocation according to the documentation: https://docs.gradle.org/current/userguide/config_gradle.html#sec:configuring_jvm_memory"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated as per your suggestions. could you please check it ? @mboetger?

@mozammal-hossain
mozammal-hossain force-pushed the fix/gradle-error-message-163801 branch from 691d5dc to 5ec7a1c Compare May 4, 2026 09:01
@jesswrd jesswrd added the CICD Run CI/CD label May 5, 2026
mboetger added a commit to mboetger/flutter that referenced this pull request May 13, 2026
mboetger added a commit to mboetger/flutter that referenced this pull request May 14, 2026
reidbaker
reidbaker previously approved these changes May 15, 2026

@reidbaker reidbaker 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.

I am not convinced that increasing the heap size will actually fix the issue for all users but I dont have better advice and we are linking to gradle docs which I do like.

mboetger
mboetger previously approved these changes May 26, 2026
@mozammal-hossain

Copy link
Copy Markdown
Contributor Author

As this branch is not updated, I'm updating this.

@mozammal-hossain
mozammal-hossain force-pushed the fix/gradle-error-message-163801 branch from 5ec7a1c to 3614a46 Compare May 27, 2026 08:24
@github-actions github-actions Bot removed the CICD Run CI/CD label May 27, 2026
@mozammal-hossain

Copy link
Copy Markdown
Contributor Author

I've run flutter analyze packages/flutter_tools/lib/src/android/ and found no issue.
Can you please add CI/CD tag? @reidbaker @mboetger

@camsim99 camsim99 added the CICD Run CI/CD label May 27, 2026
@mboetger

mboetger commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Analyze issues. See failed test

To fix, run dart format packages/flutter_tools/lib/src/android/gradle_errors.dart packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart

@mboetger
mboetger dismissed stale reviews from reidbaker and themself via 6b3ce10 June 16, 2026 21:19
@mboetger mboetger added CICD Run CI/CD and removed CICD Run CI/CD labels Jun 16, 2026
@mboetger
mboetger requested a review from reidbaker June 16, 2026 21:30
@jesswrd jesswrd added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2026
@auto-submit

auto-submit Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/185127, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@gmackall gmackall added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jun 30, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 30, 2026
@auto-submit

auto-submit Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/185127, because - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label.

@mozammal-hossain

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-07-01 at 4 00 15 PM If i rebase this with master, then merging issue will be solved, right?

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 1, 2026
@mozammal-hossain
mozammal-hossain force-pushed the fix/gradle-error-message-163801 branch from 6231238 to 3d30b86 Compare July 2, 2026 19:22
@mozammal-hossain

Copy link
Copy Markdown
Contributor Author

@gmackall, can you add CI/CD again?

@camsim99 camsim99 added the CICD Run CI/CD label Jul 6, 2026
@mboetger mboetger added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 7, 2026
Merged via the queue into flutter:master with commit 60ca823 Jul 7, 2026
169 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD 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.

After a Gradle build java.lang.OutOfMemoryError: Java heap space crash, show error with instructions for bumping Gradle memory properties

7 participants