7

I have ImageView with app:srcCompat="@drawable/my_app_img"

I get:

android.content.res.Resources$NotFoundException File res/drawable/$my_app_img__0.xml from color state list resource ID #0x7f07000a

on Android 6 and do not get it on 8 and above.

Here is the my_app_img.xml:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt"
    xmlns:tools="http://schemas.android.com/tools"
    android:width="73dp"
    android:height="103dp"
    android:viewportWidth="73"
    android:viewportHeight="103">
    <path
        android:fillAlpha="0"
        android:fillColor="#000000"
        android:pathData="M0,0l72.299,0l0,103l-72.299,0z" />
    <path android:pathData="M70.379,96.761L40.602,56.464L25.724,77.276C22.268,82.111 22.324,88.62 25.864,93.394L28.417,96.839C31.291,100.714 35.832,103 40.659,103H67.227C70.442,103 72.288,99.345 70.379,96.761Z">
        <aapt:attr name="android:fillColor">
            <gradient
                android:endColor="#FF094EC2"
                android:endX="31.7222"
                android:endY="68.3161"
                android:startColor="#FF005AF4"
                android:startX="57.4428"
                android:startY="104.487"
                android:type="linear"
                tools:targetApi="n" />
        </aapt:attr>
    </path>
    <path android:pathData="M68.592,0H38.75C36.254,0 33.907,1.188 32.431,3.199L2.949,43.369C-0.919,48.64 -0.988,55.79 2.778,61.134L19.001,84.156C19.001,80.833 20.044,77.594 21.984,74.895L71.598,5.853C73.355,3.407 71.606,0 68.592,0Z">
        <aapt:attr name="android:fillColor">
            <gradient
                android:endColor="#FF29EEFD"
                android:endX="32.6558"
                android:endY="31.6712"
                android:startColor="#FF2EB3ED"
                android:startX="6.53102"
                android:startY="64.8591"
                android:type="linear" />
        </aapt:attr>
    </path>
</vector>

Also I use:

vectorDrawables.useSupportLibrary = true
Oleg Sokolov
  • 1,134
  • 1
  • 12
  • 19

3 Answers3

16

I think the issue is related to the gradient present in the vector drawable. You have the <aapt:attr name="android:fillColor"> parameter set with a gradient there, and by looking into the documentation it seems that gradients are supported only from SDK 24+

Android vector drawable

android:fillColor

Specifies the color used to fill the path. May be a color or, for SDK 24+, a color state list or a gradient color

You could try without a gradient and see if it works.

Dan Riza
  • 397
  • 3
  • 11
  • I was getting the crash on API <= 23 for vectors within a `level-list`. `drawableEndCompat` crashed with `level-list`, but not if the vector was used directly. `drawableEnd` crashed either way. I replaced the fill and stroke gradients with solid colors and that fixed the crash, even with `drawableEnd`. I didn't really need the gradients. It took me hours to find this solution, while most answers were pointing to support library code that I'm either already using or didn't help. Thanks! – Pilot_51 Apr 30 '20 at 14:26
1

I was using ImageView and replaced it by AppCompatImageView and fixed it so it can be compatible < 24

Sattar
  • 2,453
  • 2
  • 33
  • 47
0

I am having the same problem. The reason I found it seems to be the issue of android grade plugin version.

Your vector image only supports API 24 or higher. Under 3.2.x or below, I changed from device to PNG file under API 24. However, from 3.3.x there is a crash in that part.

Are you using 3.3.x?

If so, you can use Are you using 3.2.x or below Or it works well with AndroidX.

Alternatively, you can use the Vector only in API version 24 or higher, or use a PNG file in lower versions.

I have not found a better way yet.

I hope this helps.