Android: Crash when using vector Drawables on Pre Lollipop.

First of all, we need to know one thing that

Second, Happy to advertise that They re-enabled that VectorDrawable in Android Support Library 23.4.0

Finally, what thing we need to do

static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

Still need

android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
android {
defaultConfig {
// Stops the Gradle plugin’s automatic rasterization of vectors
generatedDensities = []
}
// Flag to tell aapt to keep the attribute ids around
aaptOptions {
additionalParameters "--no-version-vectors"
}
}

If you want to do something in your code

Drawable drawable = AppCompatResources.getDrawable(getContext(), R.drawable.your_vector_drawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
}

--

--

🎓 “A person who never made a mistake never tried anything new.” —Albert Einstein

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Leo N

🎓 “A person who never made a mistake never tried anything new.” —Albert Einstein