Apktool: [Bug] Detection of "--no-res" fails for assembly for split apks.
Information
- Apktool Version (
apktool -version
) - 2.8.1 - Operating System (Mac, Linux, Windows) - Windows 10
- APK From? (Playstore, ROM, Other) - Playstore (Apkmirror)
- Java Version (
java --version
) - openjdk 17.0.7 2023-04-18
Stacktrace/Logcat
When unpacking a split APK without any resource disassembly, the packing fails:
$ apktool d --no-res --no-src split_chrome.apk -f -o _unpacked
I: Using Apktool 2.8.1 on split_chrome.apk
I: Copying raw manifest...
I: Copying raw classes.dex file...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
$ apktool b --use-aapt2 _unpacked -o _packed\1_unsigned.apk
I: Using Apktool 2.8.1
I: Copying X:\test\.\_unpacked classes.dex file...
[Fatal Error] :1:1: Content is not allowed in prolog.
I: Checking whether resources has changed...
I: Building AndroidManifest.xml...
W: X:\test\.\_unpacked\AndroidManifest.xml:1: error: not well-formed (invalid token).
W: Parse AndroidManifest.xml failed, treat it as raw file.
I: Copying raw AndroidManifest.xml...
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: X:\test\.\_packed\1_unsigned.apk
The APK gets built and can be installed:
$ adb -s emulator-5554 install _trichromelibrary.apk
Performing Streamed Install
Success
$ adb -s emulator-5554 install-multiple _base.apk _split_chrome.apk _split_feedv2.apk
Success
The app appears inside the launcher without an icon:
If you run it, it crashes with this stacktrace from logcat:
--------- beginning of crash
10-03 15:01:14.892 7575 7575 E AndroidRuntime: FATAL EXCEPTION: main
10-03 15:01:14.892 7575 7575 E AndroidRuntime: Process: com.android.chrome, PID: 7575
10-03 15:01:14.892 7575 7575 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application org.chromium.chrome.browser.base.SplitChromeApplication package com.android.chrome: java.lang.RuntimeException: Failed to parse XML configuration from 0_resource_name_obfuscated
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1466)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6720)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7872)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: Caused by: java.lang.RuntimeException: Failed to parse XML configuration from 0_resource_name_obfuscated
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:89)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.XmlConfigSource.getPerDomainConfigs(XmlConfigSource.java:55)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.ManifestConfigSource.getPerDomainConfigs(ManifestConfigSource.java:45)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.ApplicationConfig.ensureInitialized(ApplicationConfig.java:175)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.ApplicationConfig.isCleartextTrafficPermitted(ApplicationConfig.java:130)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.NetworkSecurityConfigProvider.handleNewApplication(NetworkSecurityConfigProvider.java:60)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1457)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: ... 11 more
10-03 15:01:14.892 7575 7575 E AndroidRuntime: Caused by: org.xmlpull.v1.XmlPullParserException: Unexpected start tag: found shape, expected network-security-config
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at com.android.internal.util.XmlUtils.beginDocument(XmlUtils.java:1699)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.XmlConfigSource.parseNetworkSecurityConfig(XmlConfigSource.java:315)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:83)
10-03 15:01:14.892 7575 7575 E AndroidRuntime: ... 17 more
Steps to Reproduce
apktool d --no-res --no-src split_chrome.apk -f -o _unpacked
apktool b --use-aapt2 _unpacked -o _packed\1_unsigned.apk
I’m trying these steps on 3 files of a base APK and splits. The error only happens when building an extracted split_ apk:
- base.apk OK
- split_chrome.apk ERROR
- split_feedv2.apk ERROR
APK
If this APK can be freely shared, please upload/attach a link to it. chrome_117.zip
Questions to ask before submission
- Have you tried
apktool d
,apktool b
without changing anything? Yes - If you are trying to install a modified apk, did you resign it? Yes
- Are you using the latest apktool version? Yes
About this issue
- Original URL
- State: open
- Created 9 months ago
- Comments: 15 (6 by maintainers)
I wanted to replace the package name so for me a blind string replace in all files was enough. Instead of
apktool d --no-res --no-src
I’m using this:Note: You must have case sensitivity flag enabled for the directory you’re extracting the APK to. On Windows files are case-insensitive, so different resources like “-b.xml” and “-B.xml” will collide when extracted. Enable case-sensitivity for 1 folder with
fsutil
: (Windows 10+)@vaibhavpandeyvpz docker container is only a few days old. Haven’t worked out all the kinks with it, then Android 14 dropped. So it’s on the back burner.