Apktool not associating resource IDs to correct names

Created on 10 Aug 2018  路  3Comments  路  Source: iBotPeaches/Apktool

Information

  1. Apktool Version (apktool -version) - Tested with 6231edfc and last release (v2.3.3)
  2. Operating System (Mac, Linux, Windows) - Linux
  3. APK From? (Playstore, ROM, Other) - Playstore

Stacktrace/Logcat

AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Drawable com.twitter.android:drawable/APKTOOL_DUMMY_368 with resource ID #0x7f080368
AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Resource "com.twitter.android:drawable/APKTOOL_DUMMY_368" (7f080368) is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=4 r=0x7f080368}

The APK crashes on activity start because it tries to use resource 0x7f080368, which Apktool filled with a dummy:

~
[res/values/public.xml] [...]







[...]
~

However, if we search the bytecode for that constant...

~
$ grep -r 0x7f080368
smali_classes4/dug$d.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
smali_classes2/com/twitter/composer/h$e.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
smali_classes2/com/twitter/android/bi$g.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
res/values/public.xml:
~

It seems it was meant to be ic_title_recent_logo. If we search for that drawable:

~
$ grep -r ic_title_recent_logo
smali_classes4/dug$d.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
smali_classes2/com/twitter/composer/h$e.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
smali_classes2/com/twitter/android/initialization/AppStyleInitializer.smali: sget v2, Lcom/twitter/android/bi$g;->ic_title_recent_logo:I
smali_classes2/com/twitter/android/bi$g.smali:.field public static final ic_title_recent_logo:I = 0x7f080368
res/layout/highlights_social_proof.xml:
res/layout/highlights_loading_story.xml:
~

We see it's not defined in public.xml. In fact, I changed <public type="drawable" name="APKTOOL_DUMMY_368" id="0x7f080368" /> to <public type="drawable" name="ic_title_recent_logo" id="0x7f080368" /> and the app started correctly! However, when it went to another activity it crashed again, this time asking for drawable 0x7f080661. This turned out to be twitter_logo.

So it seems Apktool is interpreting some resources as broken, and not associating them correctly. Do you have any idea why?

Steps to Reproduce

  1. apktool d <apk>

  2. It won't build:

~
I: Using Apktool 2.3.4-SNAPSHOT
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes4 folder into classes4.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes3 folder into classes3.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes5 folder into classes5.dex...
I: Checking whether resources has changed...
I: Building resources...
W: /tmp/work/Twitter_com.twitter.android/res/layout/addressbook_contacts_settings_button.xml:5: error: Error: No resource found that matches the given name (at 'layout_height' with value '@dimen/border_thickness').
W:
W: /tmp/work/Twitter_com.twitter.android/res/layout/addressbook_permission_dialog.xml:5: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/twitter_logo').
W:
W: /tmp/work/Twitter_com.twitter.android/res/layout/animated_garbage_can.xml:7: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/ic_garbage_lid').
W:
W: /tmp/work/Twitter_com.twitter.android/res/layout/animated_garbage_can.xml:8: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/ic_garbage_bottom').
W:
W: /tmp/work/Twitter_com.twitter.android/res/layout/app_rating_prompt_rich.xml:5: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/btn_ratings_star_off').
W:
[about ~500 warnings more, and appt fails to package resources]
~

  1. To workaround, I created a small transparent PNG and put copies of it in res/drawable named after every missing drawable. This, and defining two missing dimensions, made ./apktool b <apk> build the APK correctly.

  2. Sign and install the APK. It crashes. (And its crash reporter crashes too, so I had to patch the bytecode to see the real stacktrace that I posted).

If you need to reproduce the stacktrace, I can supply you with the patch and workaround. :)

APK

It's Twitter's APK (Play Store version 8900172)
Download (extension changed to .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

Most helpful comment

Okay, seems Twitter uses configuration APKs so when Play Store installs Twitter, it installs base.apk, split_config.armeabi_v7a.apk, split_config.es.apk and split_config.xxhdpi.apk together. That's why resources were missing. Tools assume just 1 apk and were giving me the base APK.

Are there plans to implement support for these kind of apps on Apktool?
Or at least, a tool that can join all these APKs into one?

All 3 comments

Okay, out of curiosity I created an x86 emulator (nexus 6, api 27 with google apis), installed the original APK and it failed on the same resource:

~
08-10 19:36:59.363 4078 4078 E AndroidRuntime: FATAL EXCEPTION: main
08-10 19:36:59.363 4078 4078 E AndroidRuntime: Process: com.twitter.android, PID: 4078
08-10 19:36:59.363 4078 4078 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twitter.android/com.twitter.android.StartActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f080368
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread.-wrap11(Unknown Source:0)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6494)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f080368
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:224)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:819)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.content.res.Resources.getDrawable(Resources.java:794)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.android.initialization.AppStyleInitializer.a(Twttr:92)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.android.initialization.AppStyleInitializer.a(Twttr:80)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.android.initialization.AppStyleInitializer.a(Twttr:29)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.android.initialization.AppStyleInitializer$1.onActivityCreated(Twttr:39)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.app.common.util.ActivityLifecycleDispatcher.a(Twttr:93)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.app.common.util.a$b.onActivityCreated(Twttr:84)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.app.common.util.a$1.onActivityCreated(Twttr:42)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.Application.dispatchActivityCreated(Application.java:197)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.Activity.onCreate(Activity.java:1015)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.support.v4.app.SupportActivity.onCreate(Twttr:66)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.support.v4.app.FragmentActivity.onCreate(Twttr:297)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.support.v7.app.AppCompatActivity.onCreate(Twttr:84)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.app.common.base.BaseFragmentActivity.onCreate(Twttr:63)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at com.twitter.android.StartActivity.onCreate(Twttr:18)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7009)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7000)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
08-10 19:36:59.363 4078 4078 E AndroidRuntime: ... 9 more
~

I honestly didn't think that the original APK could be faulty since it's from Play store and (I checked) is the exact same APK I have currently installed on my phone and it works there. I'll probably close this issue.

Okay, seems Twitter uses configuration APKs so when Play Store installs Twitter, it installs base.apk, split_config.armeabi_v7a.apk, split_config.es.apk and split_config.xxhdpi.apk together. That's why resources were missing. Tools assume just 1 apk and were giving me the base APK.

Are there plans to implement support for these kind of apps on Apktool?
Or at least, a tool that can join all these APKs into one?

Just to add more description to this bug/feature, when inspecting file where to error occurs missing resource (after decompiling .apk) is named APKTOOL_DUMMY_numberhere, so seems like already during decompiling it somehow couldn't find the proper one?

Was this page helpful?
0 / 5 - 0 ratings