Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.
build.gradle:
If you have this exception issue with drawableLeft
,drawableRight
,drawableTop
, drawableXxx
etc... And your project buildToolsVersion
> 26.0.2
.
Go check your app level gradle file, remove vectorDrawables.useSupportLibrary = true
if exists, then crash gone.
This because buildTools will dispose vector resource after 26.0.2, but somehow conflict with vectorDrawables.useSupportLibrary = true
.
Tested at 2019/03/27.
(if you can't find your buildToolsVersion
in you app level gradle file, this mean you're using Android plugin for Gradle 3.0.0 or higher, your project automatically uses a default version of the build tools that the plugin specifies. In this case your buildToolsVersion
already large than 26.0.2)
I'm surprised that this is not mentioned here yet.
This crash happens often with:
android:drawableRight
android:drawableLeft
android:drawableTop
android:drawableBottom
android:drawableStart
android:drawableEnd
A common fix is to create another drawable that wraps the drawable with <selector><item android:drawable=""></selector>
, or to set the compound drawable using code, but nowadays you can instead use:
app:drawableRightCompat
app:drawableLeftCompat
app:drawableTopCompat
app:drawableBottomCompat
app:drawableStartCompat
app:drawableEndCompat
This was added to AppCompatTextView
in appcompat 1.1.0-alpha01.
To use the attribute I've had to use AppCompat views instead of usual ones, eg. I've used AppCompatButton
instead of Button
.
Not sure if you set vectorDrawables.useSupportLibrary true
and AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
(I have both). Check this article from Nick Butcher: https://medium.com/androiddevelopers/using-vector-assets-in-android-apps-4318fd662eb9.