Behzad Bahmanyar Behzad Bahmanyar - 1 year ago 630
Android Question

Using android vector Drawables on pre Lollipop crash

I'm using vector drawables in android prior to Lollipop and these are of my libraries and tools version:

  • Android Studio : 2.0

  • Android Gradle Plugin : 2.0.0

  • Build Tools : 23.0.2

  • Android Support Library : 23.3.0

I added this property in my app level

android {
defaultConfig {
vectorDrawables.useSupportLibrary = true

Also it worth mentioning that I use an extra drawable such as LayerDrawable(layer_list) as stated in Android official Blog (link here) for setting drawables for vector drawables outside of

<level-list xmlns:android="">
<item android:drawable="@drawable/search"/>

You’ll find directly referencing vector drawables outside of
app:srcCompat will fail prior to Lollipop. However, AppCompat does
support loading vector drawables when they are referenced in another
drawable container such as a StateListDrawable, InsetDrawable,
LayerDrawable, LevelListDrawable, and RotateDrawable. By using this
indirection, you can use vector drawables in cases such as TextView’s
android:drawableLeft attribute, which wouldn’t normally be able to
support vector drawables.

When I'm using
everything works fine but when I use:


prior to Lollipop, it throws an expection

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/search_toggle.xml from drawable resource ID #0x7f0200a9

Answer Source

I think this is happening because Support Vector was disabled in latest library version: 23.3.0

According to this POST:

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 (ISSUE 205236). Using app:srcCompat and setImageResource() continues to work.

If you visit issue ISSUE 205236, it seems that they will enable in the future but memory issue should not be fixed soon:

In the next release I've added an opt-in API where you can re-enable the VectorDrawable support which was removed. It comes with the same caveats as before though (memory usage and problems with Configuration updating).

I had similar issue. So, in my case, I reverted all Icons which uses vector drawable from resource to PNG images again (since the memory issue will keep happening even after they provide an option to enable it again).

I'm not sure if this is the best option. But it fixes all the crashes to me.


They re-enabled that VectorDrawable in
Android Support Library 23.4.0

For AppCompat users, we’ve added an opt-in API to re-enable support Vector Drawables from resources (the behavior found in 23.2) via AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) - keep in mind that this still can cause issues with memory usage and problems updating Configuration instances, hence why it is disabled by default.

Maybe, build.gradle setting is now obsolete and you just need to enable it in proper activities (however, need to test).

Now, to enable it, you must do:

public class MainActivity extends AppCompatActivity {
    static {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download