Skip to content

Let Android release bundles skip --reset-cache - #59547

Merged
cortinico merged 3 commits into
react:mainfrom
lazerg:fix/issue-59543-release-bundle-reset-cache
Oct 30, 2026
Merged

cortinico merged 3 commits into
react:mainfrom
lazerg:fix/issue-59543-release-bundle-reset-cache

Conversation

@lazerg

@lazerg lazerg commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

BundleHermesCTask always passes --reset-cache to the bundle command, and there is no way to turn it off. Metro's default cache lives in os.tmpdir()/metro-cache, which every Metro on the machine shares. So each Android release bundle wipes the cache of other projects and dev servers, and on Windows it can fail with ENOTEMPTY when another Metro writes into that folder during the reset.

This adds a react.resetMetroCacheBeforeBundling Gradle property, with resetMetroCacheBeforeBundling as the unscoped name. It defaults to true, so builds work as before. Set react.resetMetroCacheBeforeBundling=false in gradle.properties to drop the flag from the bundle command. If both names are set, the scoped one wins, as with react.includeJitpackRepository.

Fixes #59543

Changelog:

[ANDROID] [ADDED] - Add react.resetMetroCacheBeforeBundling (or resetMetroCacheBeforeBundling) Gradle property to let release bundles keep the Metro cache

Test Plan:

Added ProjectUtilsTest cases for both property names (default, true, false, invalid value, and both set) and getBundleCommand_withResetMetroCacheBeforeBundlingDisabled_returnsCommandWithoutResetCache to BundleHermesCTaskTest. The existing command tests still expect --reset-cache by default. ./gradlew :react-native-gradle-plugin:test passes for both classes, and ktfmt is clean on the changed files.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 27, 2026
@lazerg

lazerg commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

The build_android failure isn't from this change. It also fails on main since the Kotlin 2.3.21 update (#59535): :gradle-plugin:shared:compileKotlin warns that API version 2.0 is deprecated, and -Werror turns that warning into an error.

@cortinico

Copy link
Copy Markdown
Contributor

/rebase

* Whether to pass `--reset-cache` to the [bundleCommand]. Disable it to keep the Metro cache
* between release builds. Default: true
*/
val resetCache: Property<Boolean> = objects.property(Boolean::class.java).convention(true)

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.

Name is too generic. resetCache can mean a bunch of things for react native. This should be more specific

@lazerg
lazerg force-pushed the fix/issue-59543-release-bundle-reset-cache branch from c4fb600 to 00b4873 Compare October 30, 2026 01:00
@lazerg

lazerg commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Renamed it to resetMetroCache and rebased onto main.

@cortinico

Copy link
Copy Markdown
Contributor

Renamed it to resetMetroCache and rebased onto main.

I think this should be called something like resetMetroCacheBeforeBundling or resetMetroCacheOnReleaseBuilds or so.

I would also suggest that we don't create a new entry in the ReactExtension but instead use a gradle property like react.resetMetroCacheBeforeBundling=false that you can put in your gradle.properties file

@lazerg

lazerg commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

I dropped the react {} option and moved this to a react.resetMetroCacheBeforeBundling Gradle property in 9197654. It defaults to true, so react.resetMetroCacheBeforeBundling=false in gradle.properties turns the reset off.

* Public property that controls whether `--reset-cache` is passed to Metro when bundling the JS
* for release builds. Default: true
*/
const val RESET_METRO_CACHE_BEFORE_BUNDLING = "react.resetMetroCacheBeforeBundling"

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.

This should follow the convention in this file. You sould accept both a SCOPED_ version of this property with react.resetMetroCacheBeforeBundling and an unscoped one with resetMetroCacheBeforeBundling

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.

Done in c50219c. It now reads both react.resetMetroCacheBeforeBundling and resetMetroCacheBeforeBundling. If both are set, the scoped one wins, same as includeJitpackRepository.

@cortinico
cortinico enabled auto-merge (squash) October 30, 2026 19:03
@meta-codesync

meta-codesync Bot commented Oct 30, 2026

Copy link
Copy Markdown

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D128660659.

@cortinico
cortinico merged commit 9add5b6 into react:main Oct 30, 2026
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Every Android release bundle empties the machine-wide Metro cache (--reset-cache)

2 participants