feat: Add auxiliary resource table loading for split APK support#3
feat: Add auxiliary resource table loading for split APK support#3Aunali321 wants to merge 1 commit intoReVanced:masterfrom
Conversation
|
Any reason this is not PRed upstream? |
|
Also, whats the reason you cant just load the resource table from the res apks split APK file and then compile the resources with aapt using that loaded table? |
|
But i recall Apktool has an API to instantiate a res table from a given apk file. Once instantiated, you can use this table to decode the xml files, this is all public api that doesnt need any PR changes. Have you tried this |
Unfortunately no, apktool-lib's existing APIs don't support this. The hard blocker is if (mPackagesById.containsKey(id)) {
throw new AndrolibException("Multiple packages: id=" + id);
}Split APKs share the same package ID (0x7f) and package name as the base APK, so you can't add a split's ResPackage to the base's ResTable. |
Summary
Add lookup-only auxiliary resource table loading so that resource IDs defined only in split APK
resources.arscfiles can be resolved during base APK decode.Motivation
When decoding a split APK bundle, the base APK's binary XML may reference resource IDs (drawables, strings, etc.) whose definitions exist only in density/config split
resources.arscfiles. SinceResourcesDecoderbuilds aResTablefrom only the base APK, these IDs are unresolvable during XML decode.ResReferenceValue.encodeAsResXml()emits@nullfor any ID wheregetReferent()fails, corrupting the decoded XML. When AAPT recompiles,@nullis compiled as resource ID 0, causing runtime crashes (Resources$NotFoundException).A full (non-split) APK does not have this problem because all resource entries are in a single
resources.arsc.Changes
ResTable: AddmAuxiliaryResSpecsandmAuxiliaryResSpecsByNamemaps for lookup-only split resource entriesResTable.getResSpec(): Fall back to auxiliary specs when the main package lookup failsResTable.getValue(): Fall back to auxiliary specs for name-based lookupsResTable.loadAuxiliaryPkg()/loadAuxiliaryPkgs(): Public API to load split resource tablesResTable.listResSpecs(): Optionally include auxiliary specs (forpublic.xmlgeneration)ResourcesDecoder: ExposeloadAuxiliaryPkgs()andsetIncludeAuxiliaryPublicXml()selectPkg(), add idempotency guard toloadMainPkg()Auxiliary specs are never added to the main package, so the decoder does not treat split-owned resources as base-owned. This avoids the decoder trying to read split files from
base.apk.Test plan
compileJavapasses@nullreferences resolved correctly, app installs and runs without crashesCompanion PRs: revanced-patcher, revanced-library, revanced-cli