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] Renaming package (or use of Brave APK at all) results in drawable not found #3346

Closed
Fmstrat opened this issue Sep 29, 2023 · 6 comments · Fixed by #3360
Closed

[BUG] Renaming package (or use of Brave APK at all) results in drawable not found #3346

Fmstrat opened this issue Sep 29, 2023 · 6 comments · Fixed by #3360
Assignees

Comments

@Fmstrat
Copy link
Contributor

Fmstrat commented Sep 29, 2023

Information

  1. Apktool Version (apktool -version) - 2.8.1
  2. Operating System (Mac, Linux, Windows) - Linux
  3. APK From? (Playstore, ROM, Other) - GitHub (Brave)
  4. Java Version (java --version) - openjdk 22-ea 2024-03-19

Stacktrace/Logcat

E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brave.personal/org.chromium.chrome.browser.ChromeTabbedActivity}: android.content.res.Resources$NotFoundException: Drawable com.brave.browser:drawable/abc_vector_test with resource ID #0x7f09014e
E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:107)
E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:237)
E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8167)
E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Drawable com.brave.browser:drawable/abc_vector_test with resource ID #0x7f09014e
E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f09014e
E AndroidRuntime: 	at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:999)
E AndroidRuntime: 	at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:735)
E AndroidRuntime: 	at android.content.res.Resources.getDrawableForDensity(Resources.java:965)
E AndroidRuntime: 	at android.content.res.Resources.getDrawable(Resources.java:880)
E AndroidRuntime: 	at android.content.Context.getDrawable(Context.java:689)
E AndroidRuntime: 	at Zs2.e(chromium-MonochromePublic.apk-stable-425813121:45)
E AndroidRuntime: 	at Zs2.f(chromium-MonochromePublic.apk-stable-425813121:3)
E AndroidRuntime: 	at Zs2.e(chromium-MonochromePublic.apk-stable-425813121:11)
E AndroidRuntime: 	at xd.p(chromium-MonochromePublic.apk-stable-425813121:55)
E AndroidRuntime: 	at xd.y(chromium-MonochromePublic.apk-stable-425813121:17)
E AndroidRuntime: 	at xd.f(chromium-MonochromePublic.apk-stable-425813121:6)
E AndroidRuntime: 	at Vc.a(chromium-MonochromePublic.apk-stable-425813121:20)
E AndroidRuntime: 	at A40.onCreate(chromium-MonochromePublic.apk-stable-425813121:27)
E AndroidRuntime: 	at QP0.onCreate(chromium-MonochromePublic.apk-stable-425813121:1)
E AndroidRuntime: 	at sX.onCreate(chromium-MonochromePublic.apk-stable-425813121:29)
E AndroidRuntime: 	at oi.J3(chromium-MonochromePublic.apk-stable-425813121:2)
E AndroidRuntime: 	at oi.onCreate(chromium-MonochromePublic.apk-stable-425813121:149)
E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7963)
E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7952)
E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:107)
E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:237)
E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8167)
E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
E AndroidRuntime: Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2<vector> tag requires viewportWidth > 0
E AndroidRuntime: 	at android.graphics.drawable.VectorDrawable.updateStateFromTypedArray(VectorDrawable.java:777)
E AndroidRuntime: 	at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:732)
E AndroidRuntime: 	at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:149)
E AndroidRuntime: 	at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1429)
E AndroidRuntime: 	at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1388)
E AndroidRuntime: 	at android.content.res.ResourcesImpl.loadXmlDrawable(ResourcesImpl.java:1062)
E AndroidRuntime: 	at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:980)
E AndroidRuntime: 	... 31 more

Steps to Reproduce

I am attempting to rename the package from com.brave.browser to com.brave.personal (to have multiple installs for multiple profiles).

Attempt to rename

OLD_PACKAGE_NAME="com.brave.browser"
OLD_APK="BraveMonoarm64.apk"
NEW_PACKAGE_NAME="com.brave.personal"
NEW_APK="BraveMonoarm64-Personal.apk"
KEYSTORE=./data/release.keystore
DATA_DIR=/tmp/data

apktool d ${OLD_APK} -o ${DATA_DIR}
sed -i "s/renameManifestPackage: null/renameManifestPackage: ${NEW_PACKAGE_NAME}/g" ${DATA_DIR}/apktool.yml
apktool b ${DATA_DIR} -o ${NEW_APK}
zipalign -p -f 4 ${NEW_APK} ${NEW_APK}.aligned.apk
mv ${NEW_APK}.aligned.apk ${NEW_APK}
/opt/android-sdk-linux/build-tools/30.0.3/apksigner sign --ks ${KEYSTORE} ${NEW_APK}

Other attempts
I have also tried multiple combinations of things, including, all of which fail similarly:

apktool d --no-assets -r -s ${OLD_APK} -o ${DATA_DIR}
apktool d -r -s ${OLD_APK} -o ${DATA_DIR}
apktool d -s ${OLD_APK} -o ${DATA_DIR}
apktool d -r ${OLD_APK} -o ${DATA_DIR}
# and
apktool b -d ${DATA_DIR} -o ${NEW_APK}

Attempt to rename manually
I have also tried renaming all text occurrences of the package name in XML and SMALI files to different extents with the same errors.

Attempt to use apktool without renaming
Running with no changes at all (zipalign and sign) causes the same error:

apktool d ${OLD_APK} -o ${DATA_DIR}
apktool b ${DATA_DIR} -o ${NEW_APK}
zipalign -p -f 4 ${NEW_APK} ${NEW_APK}.aligned.apk
mv ${NEW_APK}.aligned.apk ${NEW_APK}
/opt/android-sdk-linux/build-tools/30.0.3/apksigner sign --ks ${KEYSTORE} ${NEW_APK}

Result:

E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brave.browser/org.chromium.chrome.browser.ChromeTabbedActivity}: android.content.res.Resources$NotFoundException: Drawable com.brave.browser:drawable/abc_vector_test with resource ID #0x7f09014e

Running without signing (with and without zip aligning):

apktool d ${OLD_APK} -o ${DATA_DIR}
apktool b ${DATA_DIR} -o ${NEW_APK}
zipalign -p -f 4 ${NEW_APK} ${NEW_APK}.aligned.apk
mv ${NEW_APK}.aligned.apk ${NEW_APK}
# or
apktool d ${OLD_APK} -o ${DATA_DIR}
apktool b ${DATA_DIR} -o ${NEW_APK}

Results in an install erorr:

adb: failed to install BraveMonoarm64-Personal.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vmdl1525790083.tmp/base.apk: Attempt to get length of null array]

In all of the above, when running apktool b, I get warnings like this (a lot of them):

W: /data/tmp/res/menu/main_menu.xml:71: warning: found plain 'id' attribute; did you mean the new 'android:id' name?

And also when the APK installs, the icon is the default Android icon, and not the Brave icon.

Thoughts
Given that the error creeps up even when not changing anything (just zipalign and sign), perhaps there is something specific with the Brave APK causing issues?

APK

Downloadable: https://github.com/brave/brave-browser/releases/download/v1.58.135/BraveMonoarm64.apk

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

We do have a growing collection of these type of issues and they remain to this day to be incredibly complex to track down. With such large applications its difficult to pinpoint exactly what may be going wrong.

I'll give it a solid triage try soon and if I don't find anything, I'll close for one of these others. Thanks for the detailed research - I'll be sure to give it a solid attempt before I give up.

@auermich93
Copy link
Contributor

@iBotPeaches I can attach a very simple FDroid application (single activity) that exposes the same bug referenced in above issues:

2023-09-30 13:20:34.514 3401-3401/com.zola.bmi E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.zola.bmi, PID: 3401
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zola.bmi/com.zola.bmi.BMIMain}: android.content.res.Resources$NotFoundException: Resource ID #0x112009c
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6119)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x112009c
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
        at android.content.res.Resources.getBoolean(Resources.java:1029)
        at android.view.Window.getDefaultFeatures(Window.java:1595)
        at android.view.Window.<init>(Window.java:648)
        at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:298)
        at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:306)
        at android.app.Activity.attach(Activity.java:6619)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6119) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

This happens only if you rebuild the APK using the option --use-aapt2. The buggy behaviour must have been introduced with apktool 2.8.0, since apktool 2.7.0 doesn't fail with the --use-aapt2 option. The bug is still present in 2.8.1. After installing the app, you immediately notice that the launch icon is corrupted, at least for the attached app. Maybe this helps you to pinpoint the problem.
com.zola.bmi.apk.zip

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Sep 30, 2023

For reference, on my issue, I am not using --use-aapt2.

@iBotPeaches
Copy link
Owner

thanks - I'll wait for the Android 14 drop, rebuild aapts(2) and dig into this.

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Sep 30, 2023

@iBotPeaches Thank you. To be safe, I have tried v2.7.0 and I have the same issues with that version, so while the error message from @auermich93 is the same, these may be separate issues.

For me specifically, I am working to provide a free service (and FOSS) for users to create "renamed browsers" so they can have separate Work and Personal profiles for browsers like Brave and Firefox. Profiles seems to be a highly requested feature so this will monitor their releases and create versions for people to download and use as alternates.

I can compile Brave from source, but that's HUGE overhead for a Chromium compile, so really hoping I can get apktool working for this. Thanks!

EDIT: I've also taken what I've done to get things started in Docker and created a PR so you can take advantage of it if you would like (fully documented): #3351

@iBotPeaches
Copy link
Owner

Using this @auermich93 application as a sample, the PR linked above solves this. Either way - I'm rebuilding all the aapts shortly with Android 14 changes, but I'll close this with the above PR.

iBotPeaches added a commit that referenced this issue Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants