Search code examples
androidandroid-vectordrawable

ResourcesNotFoundException for pre-lollipop devices


What I'm already having:

This is my ImageView:

<ImageView
        android:id="@+id/play_pause"
        android:layout_width="match_parent"
        android:layout_height="@dimen/timer_button_layoutHeight"
        app:srcCompat="@drawable/play_button_vector"
        android:onClick="startOrPauseTimer"/>

I'm using Android plugin version 2.0:

classpath 'com.android.tools.build:gradle:2.0.0'

I have the vector drawable support library flag enabled in the defaultConfig of android in the app level build.gradle:

vectorDrawables.useSupportLibrary = true

I have also added the vector drawable support library dependency:

compile 'com.android.support:support-vector-drawable:23.2.1'

In the Activity class, I'm dynamically changing the vector drawable based on click listeners:

playPauseButton = (ImageView) findViewById(R.id.play_pause);
playPauseButton.setImageResource(R.drawable.play_button_vector);

The problem:

I'm getting Resource not found exception in pre-lollipop devices. The code works fine for lollipop onwards.

android.content.res.Resources$NotFoundException: File res/drawable/play_button_vector.xml from drawable resource ID #0x7f020119

I can see nothing at the place where the image should be. However, if I click on that place, where the image is supposed to be, it gets caught by the clickListener. What am I doing wrong?


Solution

  • According to a recent post from Android Developers,

    For AppCompat users, we’ve decided to remove the functionality which let you use vector drawables from resources on pre-Lollipop devices due to issues found in the implementation in version 23.2.0/23.2.1 https://code.google.com/p/android/issues/detail?id=205236. Using app:srcCompat and setImageResource() continues to work.

    Source : https://plus.google.com/+AndroidDevelopers/posts/iTDmFiGrVne