Skip to content

fix(bgp): merge res/values of embedded libraries instead of overwriting - #513

Open
KisaneNeko wants to merge 2 commits into
callstack:mainfrom
KisaneNeko:fix/bgp-aar-merge-res-values
Open

KisaneNeko wants to merge 2 commits into
callstack:mainfrom
KisaneNeko:fix/bgp-aar-merge-res-values

Conversation

@KisaneNeko

@KisaneNeko KisaneNeko commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Refs #490

Problem

Every exploded AAR stores its values in res/values/values.xml. Since #413, CopyExplodedResTask copies each library's res/ over the previous one, so only the last library's values survive. A host app with react-native-bootsplash fails at resource linking (attr/bootSplashBackground not found). On main the Expo 58 demo AAR already loses resources of expo-system-ui, expo-status-bar, expo-splash-screen and @callstack/react-native-brownfield.

Change

  • CopyExplodedResTask: merge with sdk-common's ResourceMerger, the way AGP's fused library plugin does: one ResourceSet per library, lowest priority first, and one per module static res dir on top. That gives the precedence Android uses in an app (docs): the module's own res and resValues first, then the first library. Qualifier normalization, styleable merging and file vs value collisions come from AGP.
  • LibraryResWriter: writes only the library winners the module doesn't define, so each resource ends up once in the generated dir and the "Duplicate resources" failure from Build Failure: Duplicate Resources Error During AAR Packaging with React Native Libraries #125 doesn't come back. An attr with a format declared inside styleables is written once as a top-level <attr>, with a warning when two libraries define it differently.
  • drawable/x.png, drawable/x.xml and <drawable name="x"> count as the same resource. For such files the first library now wins; before, the last one did, or both were kept and the build failed.
  • libraryOrder input, so the build cache key changes when the library order does. variant.resValues is read only when the feature is on, since AGP 9 has it off by default and warns on every read.
  • Adds sdk-common and layoutlib-api as compileOnly, at the same version as common. AGP brings both at runtime; the APIs used are unchanged from 31.12 to 32.3.1.
  • CopyExplodedResTaskTest: 16 cases, each reloading the output as one ResourceSet with validation on, as AGP does. AgpCompatibilityMatrixTest now fails if the resValues warning shows up.
  • Plugin version bumped to 2.0.0-alpha13 (yarn brownfield:plugin:version:sync). Meant to merge after fix(bgp): package local jars of embedded libraries into the AAR #512 (alpha12).

Verified with react-native-bootsplash 7.1.0 in the RN demo app: on main the consumer AndroidApp fails at processVanillaReleaseResources with the error above and the AAR misses 28 of its 44 entries; with the change none are missing and the consumer builds. Also with a local RN library that has an attr in values and a style using it in values-v31, on Expo 58 and Expo 57. Detox E2E passes for vanilla, Expo 58 and Expo 57, and a module's own app_name now wins over the one from @callstack/react-native-brownfield (on main the library's copy can replace it).

Not covered

Resources from other plugins' generated res dirs (for example google-services) don't count as the module's own: reading them would include this task's own output.

callstack#413 made each library's res/values/values.xml replace the previous
one, since every exploded AAR stores its values under that path.
Merge them with sdk-common's ResourceMerger instead, like AGP's fused
library plugin does: one resource set per library, with the module's
own res and resValues on top, so the module wins, then the first
library.

callstack#125 came from keeping a resource twice in one dir, so only the winners
are written, and an attr is defined once.

Refs callstack#490
@KisaneNeko
KisaneNeko force-pushed the fix/bgp-aar-merge-res-values branch from fa112b7 to 7648ca5 Compare October 23, 2026 11:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant