Invalid drawable tag vector

后端 未结 14 959
小蘑菇
小蘑菇 2020-12-28 12:34

Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.

build.gradle:

相关标签:
14条回答
  • 2020-12-28 13:03

    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)

    0 讨论(0)
  • 2020-12-28 13:05

    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.

    0 讨论(0)
提交回复
热议问题