Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Detection of "--no-res" fails for assembly for split apks. #3364

Open
weary-adventurer opened this issue Oct 3, 2023 · 15 comments
Open
Labels

Comments

@weary-adventurer
Copy link

Information

  1. Apktool Version (apktool -version) - 2.8.1
  2. Operating System (Mac, Linux, Windows) - Windows 10
  3. APK From? (Playstore, ROM, Other) - Playstore (Apkmirror)
  4. 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:

image

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

  1. apktool d --no-res --no-src split_chrome.apk -f -o _unpacked
  2. 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

  1. Have you tried apktool d, apktool b without changing anything? Yes
  2. If you are trying to install a modified apk, did you resign it? Yes
  3. Are you using the latest apktool version? Yes
@iBotPeaches
Copy link
Owner

As you mention the icon becoming corrupted. I believe this may resolve it - #3360

I'm testing this out on another ticket and no longer seeing icon corruption - just haven't built mac binaries yet, so its not mergable.

@weary-adventurer
Copy link
Author

Same error using aapt2_64.exe from here:

$ apktool b --aapt aapt2_64.exe _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

@iBotPeaches
Copy link
Owner

Same error using aapt2_64.exe from here:

aapt isn't invoked at that point. I'd hold till next release for the moment unless you want to really mess with bleeding edge builds and fresh aapts.

@weary-adventurer
Copy link
Author

I can test it pretty quickly so I don't see why not - if you have an apktool.jar of the new build I'll just swap it out and rerun the command.

@iBotPeaches
Copy link
Owner

I can test it pretty quickly so I don't see why not - if you have an apktool.jar of the new build I'll just swap it out and rerun the command.

All master commits trigger a build as an attachment https://github.com/iBotPeaches/Apktool/actions/runs/6391710817

It's bleeding edge master builds.

@weary-adventurer
Copy link
Author

Same problem:

$ apktool b --use-aapt2 _unpacked -o _packed\1_unsigned.apk
I: Using Apktool v2.8.1-77-448440b5-SNAPSHOT
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

@iBotPeaches
Copy link
Owner

Okay to the backlog it goes. Sorry! Will focus after I finish up 2.9.x, thanks for testing.

@iBotPeaches iBotPeaches added the Bug label Oct 3, 2023
@vaibhavpandeyvpz
Copy link

I'm having similar issue as the OP, having installed the latest framework-res.apk (matches with compileSdkVersion) pulled from emulator and it could not build, without any changes.

framework-res.apk.zip

I: Using Apktool 2.8.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: <generated>:0: error: Resource entry @null is already defined.
W: <generated>:0: Originally defined here.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:9: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:15: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:20: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:39: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:47: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:106: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:112: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:163: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:189: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:196: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:210: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:229: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:238: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:297: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:323: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:347: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:380: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:384: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:388: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:392: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:396: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:453: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:522: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:560: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:581: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:590: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:701: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:723: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:743: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:748: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:754: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:760: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:807: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:815: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:838: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:846: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:949: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:982: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:986: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:995: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1102: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1112: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1241: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1248: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1253: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1343: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1360: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1368: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1377: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1461: error: Error: No resource found that matches the given name: id '@null'.
W: 
W: /some/place/on/my/pc/res/values/attrs.xml:1515: error: Error: No resource found that matches the given name: id '@null'.
W: 
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/xm/qztxy4kj2z7fj225d95_rdy80000gn/T/brut_util_Jar_15258914466107107889730254320349036517.tmp, p, --forced-package-id, 127, --version-code, 730, --version-name, 0.15.2, --no-version-vectors, -F, /var/folders/xm/qztxy4kj2z7fj225d95_rdy80000gn/T/APKTOOL15957171665988370597.tmp, -e, /var/folders/xm/qztxy4kj2z7fj225d95_rdy80000gn/T/APKTOOL14549013480625325211.tmp, -0, arsc, -I, /Users/vpz/Library/apktool/framework/1.apk, -S, /some/place/on/my/pc/res, -M, /some/place/on/my/pc/AndroidManifest.xml]

@vaibhavpandeyvpz
Copy link

I also tried using the build from master via Docker, fails on building resources with a weird error.

% docker run --rm -it --platform=linux/amd64 -v .:/app -w /app ghcr.io/ibotpeaches/apktool:master sh
Unable to find image 'ghcr.io/ibotpeaches/apktool:master' locally
master: Pulling from ibotpeaches/apktool
707e32e9fc56: Pull complete 
1ed42af34167: Pull complete 
4014d94a7eba: Pull complete 
14869f03ca47: Pull complete 
66aa4b4e2abb: Pull complete 
497d3d8587e8: Pull complete 
9c9c5a403682: Pull complete 
Digest: sha256:fa76918b53454719ca277dee0f1623d090c6220311ad6630d7b4142b51744ea6
Status: Downloaded newer image for ghcr.io/ibotpeaches/apktool:master
# apktool if framework-res.apk
I: Framework installed to: /root/.local/share/apktool/framework/1.apk
# apktool d sourceapp.apk -o targetapp
I: Using Apktool 2.8.2-dirty on sourceapp.apk
I: Loading resource table...
I: Decoding file-resources...
I: Loading resource table from file: /root/.local/share/apktool/framework/1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory
# apktool b targetapp -o targetapp.apk
I: Using Apktool 2.8.2-dirty
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
This command is not for general use and should only be run as the result of a call to
ProcessBuilder.start() or Runtime.exec() in a java application
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_47934858844575977317641301982171960779.tmp, compile, --dir, /app/targetapp/res, --legacy, -o, /app/targetapp/build/resources.zip]

@iBotPeaches
Copy link
Owner

@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.

@vaibhavpandeyvpz
Copy link

vaibhavpandeyvpz commented Oct 6, 2023

I just tried taking out the /usr/local/bin/apktool.jar from the container and run it on M2 Pro machine natively, get different errors. Please see below:

% java -jar apktool.jar d sourceapp.apk -o targetapp 
I: Using Apktool 2.8.2-dirty on sourceapp.apk
I: Loading resource table...
I: Decoding file-resources...
I: Loading resource table from file: /heavenly/place/Library/apktool/framework/1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory
% java -jar apktool.jar b targetapp -o targetapp.apk
I: Using Apktool 2.8.2-dirty
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /heavenly/place/targetapp/res/animator/2130837504.xml:4: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/animator/2130837504.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/animator/2130837519.xml:4: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/animator/2130837519.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/color/2131099847.xml:5: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/color/2131099847.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/color/2131099848.xml:5: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/color/2131099848.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout-land/2131492956.xml:2: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout-land/2131492956.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout-land/2131492963.xml:4: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout-land/2131492963.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout-ldrtl/2131492960.xml:2: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout-ldrtl/2131492960.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout/2131492867.xml:2: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout/2131492867.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout/2131492869.xml:2: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout/2131492869.xml: error: file failed to compile.
W: /heavenly/place/targetapp/res/layout/2131492887.xml:6: error: not well-formed (invalid token).
W: /heavenly/place/targetapp/res/layout/2131492887.xml: error: file failed to compile.
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/var/folders/xm/qztxy4kj2z7fj225d95_rdy80000gn/T/brut_util_Jar_74481588292727980021117246174335452358.tmp, compile, --dir, /heavenly/place/targetapp/res, --legacy, -o, /heavenly/place/targetapp/build/resources.zip]

@weary-adventurer
Copy link
Author

weary-adventurer commented Oct 6, 2023

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:

7z x -ssc -o".\unpacked" "target.apk"
pushd ".\unpacked"
for /r %%f in (*.*) do (
    rem replace ascii and utf16le of string in all files
    binaryreplace -s com.android.chrome -r com.android.chr117 -f %%f
)
for /r %%f in (*.dex) do (
    rem file[12..32] = sha1(file[32..])
    rem file[8..12] = adler32(file[12..])
    dexchecksum %%f
)
popd
7z a -tzip -ssc -mx=0 "1_unsigned.apk" ".\unpacked\*"
zipalign -p -f 4 "1_unsigned.apk" "2_zipaligned.apk"
apksigner sign --key ".\key" --cert ".\cert" --out "3_signed.apk" "2_zipaligned.apk"

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+)

fsutil file setCaseSensitiveInfo .\unpacked enable

@vaibhavpandeyvpz
Copy link

That’s clever. I’ll check this soon and let you know if it works for me too. Me too only want to change the package name. Thanks!

@vaibhavpandeyvpz
Copy link

Oh, these are for Command Prompt. I'm on Mac 😬

@iBotPeaches
Copy link
Owner

Took a look at this again - the warning during compilation is because there is no resources.arsc for this logic to detect if resource disassembly was enabled or not. Seems harmless, but annoying.

No good way to resolve because the flag is used during disassembly and not persisted towards assembly. Relying on the resources.arsc was a good method until split apks came out.

For the crash issues - I can't investigate. Don't have anything rooted at the moment to support reinstalling system apps like Chrome.

So I'll place this into backlog.

@iBotPeaches iBotPeaches changed the title [BUG] Error building AndroidManifest of unmodified split Chrome APK [Bug] Detection of "--no-res" fails for assembly for split apks. Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants