androidexceptionsvgdrawable

ResourcesNotFoundException when resource available (API 22 and 23 devices)


I get this crash only on API 22 and 23 devices.

(android.content.res.Resources$NotFoundException: File res/drawable/show_empty_state.xml from drawable resource ID #0x7f080156 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640) at android.content.res.Resources.loadDrawable(Resources.java:2540) at android.content.res.Resources.getDrawable(Resources.java:806) at android.content.Context.getDrawable(Context.java:458) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:358) at com.myProj.utils.EmptyStateView.setImage(EmptyStateView.java:55) at com.myProj.tab_two.ShowFragment.onCreateView(ShowFragment.java:111) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)

The resource is definitely there and it works fine on higher devices. The only recent change i did was replace a new vector image using SVG for show_empty_state. I did look at some other related questions. Could not find an answer so far. Any help is appreciated. Thanks.


Solution

  • The crash was because the vector asset had gradient tag for <24 devices.

    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 (See GradientColor and GradientColorItem). If this property is animated, any value set by the animation will override the original value. No path fill is drawn if this property is not specified.

    Replacing the

    <gradient android:endX="45300.0" android:endY="-86698.0"
           <android:startX="45300.0" android:startY="-3118.0" android:type="linear">
           <item android:color="#FF1AA186" android:offset="0.0"/>
           <item android:color="#FF23B899" android:offset="1.0"/>
     </gradient>
    

    with

    android:fillColor="#FF1AA186"
    

    fixes it.

    Better would be to replace the asset with a non-gradient one for <24 sdk.