ianhanniballake ianhanniballake - 2 years ago 133
Android Question

AppCompat 23.3 Support Vectors no longer work?

I was using the support vector drawables added in Support Library 23.2 along with AppCompat. I was using vector drawables both with

and inside a
so I could use them with
for my TextView.

Since upgrading to the 23.3.0 version of AppCompat, only the vectors in
are working. Whenever I reference it the other way I get

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.package.name/.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class Button
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #14: invalid drawable tag vector
at android.graphics.d

What changed that now causes my support vector drawables to fail in some cases?

Answer Source

Update: They enable it again in Support Library 23:

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.

Check this link: 23.4.0 available now

As per the release announcement for Android Support Library 23.3:

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, https://code.google.com/p/android/issues/detail?id=204708 ]. Using app:srcCompat and setImageResource() continues to work.

So this is an expected behavior change. You'll have to use non-vector graphics for any case not handled by srcCompat.

If you'd like to continue to use vectors prior to API 21, you can remove the line

vectorDrawables.useSupportLibrary = true

(or the equivalent if you using the 1.5 Gradle plugin as shown in the 23.2 blog post).

This will cause Android Studio to generate PNGs at compile time for apps with a minSdkVersion less than API 21 while using your vectors on API 21+ devices, allowing you to keep the same code as with 23.2.1 at the cost of additional APK size.

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