Can't convert to ComplexColor: type=0x1 #1382

xpirt opened this Issue Dec 16, 2016 · 4 comments


None yet

2 participants

xpirt commented Dec 16, 2016


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


Steps to Reproduce

Application crashes with no modifications done to it, after decompilation/compilation.

  1. apktool d LGSystemUI.apk
  2. apktool b LGSystemUI





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

I need to refresh myself on colors for Android. This application is huge so going to run some localized tests so I can pinpoint the problem.

We have

    <color name="fake_shadow_start_color">#44000000</color>
    <color name="notification_guts_disabled_slider_color">@android:color/material_grey_300</color>
    <color name="qs_vector_btn">?qs_panel_highlight</color>
    <color name="pin_color">?android:colorAccent</color>
    <color name="accent_material_dark">@color/material_deep_teal_200</color>

So about every syntax format possible for colors. Apktool may be decoding incorrectly or building incorrectly. Will need to investigate at smaller size.

xpirt commented Dec 19, 2016 edited

Today I investigated about this issue and I found out the cause.
The good thing is that all the colors you mentioned are decoded properly, the bad thing is that what is not encoded properly is a reference to a framework attribute.

More specifically:


in res/layout/qs_paged_tile_layout.xml, then:

< color name="qs_detail_transition">@com.lge:attr/textColorPrimaryType4< /color>

in res/values/colors.xml, and:

< item name="qs_edit_panel_drag_highlight">@com.lge:attr/colorAccentType3< /item>

in res/values/colors.xml.

So, basically all (and the only ones) references to color attrs in lge-res.apk in this format: @com.lge:attr/xxxxxxx, which in the framework's attrs.xml are reference|color.

Example, from attrs.xml:

< attr name="textColorPrimaryType3" format="reference|color" />

Finally, replacing those references with standard color types (eg. #ffffffff) fixed the issue.


Okay, so let me follow this to get things straight.

  1. We find in res/layout/qs_paged_tile_layout.xml
  1. So we follow that to the attribute based on the pkg name to lge-res.apk and res/value/attrs.xml
    <attr name="textColorPrimaryType3" format="reference|color" />
  1. Its either a reference or a color, so lets check out res/value/styles.xml in lge-res.apk.
    <style name="Theme.LGE.Default" parent="@android:style/Theme.Material.Light">
        <item name="textColorPrimaryType1">@color/primary_text_default_material_light_80</item>
        <item name="textColorPrimaryType2">@color/primary_text_default_material_light_70</item>
        <item name="textColorPrimaryType3">@color/primary_text_default_material_light_60</item>
  1. So lets go checkout res/values/colors.xml in lge-res.apk.
    <color name="primary_text_default_material_light_80">#cc000000</color>
    <color name="primary_text_default_material_light_70">#b2000000</color>
    <color name="primary_text_default_material_light_60">#99000000</color>
  1. So going to rebuild LGSystemUI and decode it again.


        A: android:textColor(0x01010098)=(type 0x8)0x201000d


        A: android:textColor(0x01010098)=(type 0x7)0x201000d

So we improperly converted the resource from type 8 to type 7.

     * The <var>data</var> holds a dynamic res table reference, which needs to be
     * resolved before it can be used like TYPE_REFERENCE
    public static final int TYPE_DYNAMIC_REFERENCE = 0x07;
     * The <var>data</var> an attribute resource identifier, which needs to be resolved
     * before it can be used like a TYPE_ATTRIBUTE.
    public static final int TYPE_DYNAMIC_ATTRIBUTE = 0x08;

So the correct type was TYPE_DYNAMIC_ATTRIBUTE, but then it became TYPE_DYNAMIC_REFERENCE which probably led to the errors.

I improperly patched the newly added TYPE_DYNAMIC_ATTRIBUTE as

            case TypedValue.TYPE_DYNAMIC_REFERENCE:
            case TypedValue.TYPE_DYNAMIC_ATTRIBUTE:
                return newReference(value, rawValue);

so I need to take another look at it.

xpirt commented Dec 20, 2016

You're right, treating TYPE_DYNAMIC_ATTRIBUTE as TYPE_ATTRIBUTE fixes the issue.

Sent also a pull request, 983e0ad.

Tested and working just fine, thank you!

@iBotPeaches iBotPeaches closed this in #1385 Dec 20, 2016
@iBotPeaches iBotPeaches added a commit that referenced this issue Dec 20, 2016
@iBotPeaches update changelog for #1382 8a27813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment