devendroid / VectorChildFinder

VectorChildFinder helps to find inner elements of vector drawable like path and group.
Apache License 2.0
202 stars 41 forks source link

Can't find ColorStateList from drawable resource ID #0x7f080006 #10

Open tudorsirbu opened 5 years ago

tudorsirbu commented 5 years ago

The library seems to crash whenever it tries inflate a vector which as a gradient in it. (see example file below)

<vector xmlns:aapt="http://schemas.android.com/aapt"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="27dp"
        android:height="32dp"
        android:viewportHeight="31.7"
        android:viewportWidth="27">
    <path
        android:fillColor="#7d173a"
        android:pathData="M13.4,0a54.4,54.4 0,0 1,5.9 0.5,40.5 40.5,0 0,1 5.6,1.5 35.2,35.2 0,0 1,1.6 6.4,46.8 46.8,0 0,1 0.5,7c0,3 -1.2,6.1 -3.7,9.4a20.3,20.3 0,0 1,-9.8 6.9,18.8 18.8,0 0,1 -9.8,-6.9c-2.4,-3.3 -3.7,-6.4 -3.7,-9.4a46.8,46.8 0,0 1,0.5 -7A35.2,35.2 0,0 1,2.1 2,33 33,0 0,1 7.5,0.5 54.4,54.4 0,0 1,13.4 0Z"/>
    <path
        android:fillColor="#fff"
        android:pathData="M17.8,15.7c1,0.2 5.8,1.5 5.5,2.5a13.5,13.5 0,0 1,-3.5 5.8,22.7 22.7,0 0,1 -6.4,4 22.7,22.7 0,0 1,-6.4 -4,12.9 12.9,0 0,1 -3.5,-5.9c-0.3,-1 4.6,-2.2 5.5,-2.4a33.3,33.3 0,0 1,4.4 -0.4A33.3,33.3 0,0 1,17.8 15.7Z"/>
    <path
        android:fillAlpha="0.24"
        android:fillColor="#FF000000"
        android:pathData="M22.3,4.3a32.3,32.3 0,0 1,1.3 6.5c0.4,4.7 -0.1,6.9 -0.3,7.4a13.5,13.5 0,0 1,-3.5 5.8,22.7 22.7,0 0,1 -6.4,4L13.4,2.7a21.4,21.4 0,0 1,4.5 0.5A25.7,25.7 0,0 1,22.3 4.3Z"
        android:strokeAlpha="0.24"/>
    <path android:pathData="M19.3,0.5a40.5,40.5 0,0 1,5.6 1.5,35.2 35.2,0 0,1 1.6,6.4 46.8,46.8 0,0 1,0.5 7c0,3 -1.2,6.1 -3.7,9.4a20.3,20.3 0,0 1,-9.8 6.9,18.8 18.8,0 0,1 -9.8,-6.9c-2.4,-3.3 -3.7,-6.4 -3.7,-9.4a46.8,46.8 0,0 1,0.5 -7A35.2,35.2 0,0 1,2.1 2,33 33,0 0,1 7.5,0.5 54.4,54.4 0,0 1,13.4 0,54.4 54.4,0 0,1 19.3,0.5Z">
        <aapt:attr name="android:fillColor">
            <gradient
                android:endX="20.4"
                android:endY="1.2154024"
                android:startX="8.4"
                android:startY="20.467602"
                android:type="linear">
                <item
                    android:color="#00FFFFFF"
                    android:offset="0"/>
                <item
                    android:color="#66FFFFFF"
                    android:offset="1"/>
            </gradient>
        </aapt:attr>
    </path>
</vector>

The stacktrace is

        at android.content.res.ResourcesImpl.loadColorStateList(ResourcesImpl.java:1042)
        at android.content.res.Resources.loadColorStateList(Resources.java:1041)
        at android.content.res.TypedArray.getColor(TypedArray.java:469)
        at com.devs.vectorchildfinder.TypedArrayUtils.getNamedColor(TypedArrayUtils.java:54)
        at com.devs.vectorchildfinder.VectorDrawableCompat$VFullPath.updateStateFromTypedArray(VectorDrawableCompat.java:1623)
        at com.devs.vectorchildfinder.VectorDrawableCompat$VFullPath.inflate(VectorDrawableCompat.java:1590)
        at com.devs.vectorchildfinder.VectorDrawableCompat.inflateInternal(VectorDrawableCompat.java:614)
        at com.devs.vectorchildfinder.VectorDrawableCompat.inflate(VectorDrawableCompat.java:498)
        at com.devs.vectorchildfinder.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:456)
        at com.devs.vectorchildfinder.VectorDrawableCompat.create(VectorDrawableCompat.java:437)

Has anyone got any idea how I can fix this or get around it?

Thanks!

tachyonlabs commented 4 years ago

Same problem here.

ggets commented 4 years ago

Encountered the same issue. It is indeed because of gradients. Code searches for the android:fillColor attribute and can't find it. You can, however, fix this quick and dirty. split your svg into 2 separate ones - one with gradients and one with solid fills. then overlay them inside a FrameLayout, or anything else more suitable.