question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manifest not reencoding (corrupt XML binary file?) causing error signing/installing

See original GitHub issue

Information

  1. Apktool Version (apktool -version) - 2.4.1
  2. Operating System (Mac, Linux, Windows) - macOS
  3. APK From? (Playstore, ROM, Other) - Other

Stacktrace/Logcat

Decoding with -rs --force-manifest

I: Using Apktool 2.4.1 on 67f32da161bc63a8ac5a07c1df819e63.apk
I: Copying raw resources...
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /Users/aptmas/Library/apktool/framework/1.apk
I: Regular manifest package...
I: Copying raw classes.dex file...
I: Copying raw classes3.dex file...
I: Copying raw classes5.dex file...
I: Copying raw classes6.dex file...
I: Copying raw classes4.dex file...
I: Copying raw classes2.dex file...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

Encoding without flags

I: Using Apktool 2.4.1
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes.dex file...
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes3.dex file...
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes2.dex file...
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes6.dex file...
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes5.dex file...
I: Copying 67f32da161bc63a8ac5a07c1df819e63 classes4.dex file...
I: Checking whether resources has changed...
I: Copying raw resources...
I: Copying libs... (/lib)
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk...

ApkSigner

Exception in thread "main" com.android.apksig.apk.MinSdkVersionException: Failed to determine APK's minimum supported platform version. Use --min-sdk-version to override
	at com.android.apksigner.ApkSignerTool.sign(ApkSignerTool.java:372)
	at com.android.apksigner.ApkSignerTool.sign(ApkSignerTool.java:123)
	at com.android.apksigner.ApkSignerTool.main(ApkSignerTool.java:84)
Caused by: com.android.apksig.apk.MinSdkVersionException: Unable to determine APK's minimum supported Android platform version: malformed binary resource: AndroidManifest.xml
	at com.android.apksig.apk.ApkUtils.getMinSdkVersionFromBinaryAndroidManifest(ApkUtils.java:384)
	at com.android.apksig.ApkSigner.getMinSdkVersionFromApk(ApkSigner.java:857)
	at com.android.apksig.ApkSigner.sign(ApkSigner.java:260)
	at com.android.apksig.ApkSigner.sign(ApkSigner.java:193)
	at com.android.apksigner.ApkSignerTool.sign(ApkSignerTool.java:366)
	... 2 more
Caused by: com.android.apksig.internal.apk.AndroidBinXmlParser$XmlParserException: No XML chunk in file
	at com.android.apksig.internal.apk.AndroidBinXmlParser.<init>(AndroidBinXmlParser.java:101)
	at com.android.apksig.apk.ApkUtils.getMinSdkVersionFromBinaryAndroidManifest(ApkUtils.java:345)
	... 6 more

Installation

INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed to parse /data/app/vmdl1094509404.tmp/base.apk: Corrupt XML binary file

Steps to Reproduce

  1. Use apktool to decode APK with -rs --force-manifest (no error) - log above
  2. Use apktool to encode APK without any changes (no error) - log above
  3. Try to sign/install APK and get the errors above

I have also tried to do it without flags but while it decodes correctly, when it’s building it’ll show errors related to “No resource identifier found for attribute” eventually failing for:

brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/nf/t6_29zc50pb_lw5ww_p74rym0000gp/T/brut_util_Jar_6758575029498112036.tmp, p, --forced-package-id, 127, --min-sdk-version, 19, --target-sdk-version, 28, --version-code, 4226, --version-name, 1.9.13c, --no-version-vectors, -F, /var/folders/nf/t6_29zc50pb_lw5ww_p74rym0000gp/T/APKTOOL6277513217225256484.tmp, -e, /var/folders/nf/t6_29zc50pb_lw5ww_p74rym0000gp/T/APKTOOL7421589631204875490.tmp, -0, arsc, -I, /Users/x/Library/apktool/framework/1.apk, -S, /Users/x/Desktop/!/apktools/67f32da161bc63a8ac5a07c1df819e63/res, -M, /Users/x/Desktop/!/apktools/67f32da161bc63a8ac5a07c1df819e63/AndroidManifest.xml]

By looking inside the APK I have noticed the AndroidManifest.xml isn’t getting reencoded even if it builds successfully, so perhaps this is why the apksigner complains about malformed XML?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
natelastnamecommented, Sep 14, 2020

Not sure. I added support for API 29 (Q) and API 30 ® and API 31 (S) which are used as those codename values which I imagine ApkSigner cannot handle.

This was a recent change that happened around version M, because it crashed Apktool as well until we wrote code to automatically remap those (ie Q -> 29). That has not been happening with anything after Q as we haven’t had an update in almost a year.

If this commit doesn’t solve it - 3101a05, then its a bug in ApkSigner and thus not Apktool.

I tried building the repo and reproducing this bug running apktool from the jar file. Unfortunately, it was not fixed.

My understanding of the problem is that the AndroidManifest.xml is not converted back to AXML by apktool when building after a decompile with --force-manifest. This can be confirmed by unzipping the corrupted APK and checking AndroidManifest.xml.

Does that change your opinion about this issue? Thank you and sorry if I’m misunderstanding the scope of apktool.

1reaction
fgroupindonesiacommented, Nov 20, 2021

omg… i was experiencing the same problems…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merged AndroidManifest only contains the Library content
I have checked APK analyzer in AndroidStudio, and I found that AndroidManifest.xml not contains any code related to my application, it only ...
Read more >
"Corrupt XML binary file" error when adding a PNG to res ...
I'm seeing an odd error when adding a PNG file to the res/drawable ... Corrupt XML binary file ... The activity name in...
Read more >
Re-encoding corrupt files using iTunes - Serato Support
Open the files window list and click 'Convert' - 'Create MP3 Version' and iTunes will do the rest. Please note that this will...
Read more >
error in manifest or policy file invalid xml syntax
I checked the event log and found an error in manifest or policy files at line 0 invalid xml syntax (completely blank what...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found