2

I've had this question for a while but I've always wondered: why do I need to declare

vectorDrawables.useSupportLibrary = true

for my API 19 device but not my API 29 device?

They are both loading the same icon I imported, but why does API 19 devices need to declare that other it gives you a compile time error.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
  • does -> help https://developer.android.com/guide/topics/graphics/vector-drawable-resources#vector-drawables-backward-solution also see https://stackoverflow.com/questions/40678947/how-to-properly-use-backwards-compatible-vector-drawable-with-the-latest-android – Abhinav Chauhan Jul 08 '20 at 02:21

1 Answers1

1

The reason for this is that native (as in, built into the Android framework) support for vector drawables was added in API 21 (Android 5.0 Lollipop).

The vectorDrawables.useSupportLibrary option enables a backward-compatibility feature in the Android support library (now known as AndroidX AppCompat) that allows it to load vector drawables at Runtime via the VectorDrawableCompat and AnimatedVectorDrawableCompat classes.

It is also possible to configure the Android Gradle Plugin to convert the vector images to PNG files at build time for use on pre–API 21 devices, but this defeats many of the benefits of using vector drawables in the first place, such as smaller app size.

Ryan M
  • 18,333
  • 31
  • 67
  • 74