Skip to content

Fix Apktool resource decoding bugs#17

Open
Sleeeee wants to merge 3 commits into
TheDauntless:masterfrom
Sleeeee:master
Open

Fix Apktool resource decoding bugs#17
Sleeeee wants to merge 3 commits into
TheDauntless:masterfrom
Sleeeee:master

Conversation

@Sleeeee

@Sleeeee Sleeeee commented May 4, 2026

Copy link
Copy Markdown

On obfuscated APKs, Apktool will struggle with resource decoding and throw different kinds of errors, which propagate to patch-apk when trying to rebuild an APK. We can catch the error logs and fix them programmatically, and re-run the build command.

Since Apktool's error printing is capped to 20 errors, we can do trial and error to fix them 20 at a time. The time to fully fix can be increased a lot depending on the amount of times it has to rebuild.

Error 1 : namespacing error

W: /tmp/tmp6ug84c13/apk_decoded/res/animator/APKTOOL_RENAMED_0x7f020002.xml:4: error: attribute android:APKTOOL_RENAMED_0x7f0409ce not found.

See this issue for details about this error. Basically, it assigns the android: namespace to properties that should be assigned app:.

From patch-apk, we can retrieve the filename and attribute that caused the error, then remove the android: prefix.

Error 2 : duplicate attributes

W: /tmp/tmpppawd3a1/apk_decoded/res/font/alternative.xml:4: error: duplicate attribute.
W: /tmp/tmpppawd3a1/apk_decoded/res/font/alternative.xml: error: file failed to compile.

We can match duplicates inside their files with a regex and keep only one occurence.

Error 3 : incompatible flags

W: /tmp/tmpofrmlkwo/apk_decoded/res/layout/telco_buy_image_header.xml:9: error: '0x0' is incompatible with attribute foregroundGravity (attr) flags [bottom=80, center=17, center_horizontal=1, center_vertical=16, clip_horizontal=8, clip_vertical=128, fill=119, fill_horizontal=7, fill_vertical=112, left=3, right=5, top=48].

Enumerations with no actual value will be decoded as an invalid 0x0 value. We can remove this attribute completely.

Example output on a test app:

$ patch-apk --extract-only com.example.myapp
[*] Using package: com.example.myapp
[*] Pulled 2 APK(s)
[*]  - base.apk
[*]  - split_config.arm64_v8a.apk
[*] Split APK set detected (2)
[*] Disassembling base.apk with apktool
[*] Disassembling split_config.arm64_v8a.apk with apktool
[*] Merging split APKs into base
[*] Detected duplicate attribute error, trying to resolve automatically
[*] Removed 5 duplicates, restarting build
[*] Detected resource namespace mismatch, trying to resolve automatically
[*] Fixed 20 broken namespaces, restarting build
[*] Detected resource namespace mismatch, trying to resolve automatically
[*] Fixed 20 broken namespaces, restarting build
[*] Detected resource namespace mismatch, trying to resolve automatically
[*] Fixed 20 broken namespaces, restarting build
[*] Detected resource namespace mismatch, trying to resolve automatically
[*] Fixed 19 broken namespaces, restarting build
[*] Detected resource namespace mismatch, trying to resolve automatically
[*] Fixed 5 broken namespaces, restarting build
[*] Detected incompatible flags error, trying to resolve automatically
[*] Removed 1 incompatible flags, restarting build
[*] Saved APK: com.example.myapp.apk

@Sleeeee

Sleeeee commented May 13, 2026

Copy link
Copy Markdown
Author

Error 1 fix was merged in Apktool, so catching this error might not be needed anymore. Maybe it's still relevant to match error patterns even though they're not supposed to appear ?

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