Skip to content

Conversation

@Surendrajat
Copy link

@Surendrajat Surendrajat commented Nov 4, 2025

This PR adds automatic resolution of @null drawable references that
appear in binary XML files when merging Android App Bundles (AAB) to APK.

Disclaimer: AI assisted but properly tested by me. I can't share the apk but the code
is pretty self explanatory and you don't need to merge it until you can find another apk
with same issue. Just leaving it out there if someone bumps in same issue.

Problem:

When merging split APKs, some drawable XML files contain references
to @null (ValueType.REFERENCE with data=0). These unresolved references
cause Resources$NotFoundException crashes at runtime when the app tries
to load these resources.

Solution:

  1. Scan drawable XML files for null references during merge
  2. Use fuzzy keyword matching to find corresponding PNG overlay resources
  3. Look up resource IDs from the package table
  4. Update binary XML attributes using setData() API
Implementation Details
  • Added resolveResourceOverlays() method to ApkBundle.mergeModules()
  • Uses PackageBlock.getResource() for proper resource ID lookup
  • Updates binary XML with ResXmlAttribute.setData() (not setValueAsString)
  • Fuzzy matching handles naming variations between XML and PNG files
  • Minimal performance impact (~50-100ms for typical apps)

Results from testing:

Before: <item android:drawable="@null" />
After: <item android:drawable="@drawable/abc_btn_switch_to_on_00012" />

Notes:

  • Improve fuzzy matching or find a better another approach if any

@REAndroid
Copy link
Owner

Looks like this intended for one specific app.
We should not rely on hard coded values like the one you used "res/drawable/", "state_checked" ... , btw there is built in function to check if the file is bnary xml ResFile#isBinaryXml()

We need some samples to fully understand this issue

  • If your sample apk meant not to be shared for public but don't mind to share to me, then you can send to me privately.
  • If your sample apk NOT to be shared to anyone, you can strip off secret parts or make simple apks from scratch to demonstrate this issue.

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.

2 participants