Using Vector Drawable Compat

Guilherme R picture Guilherme R · Dec 19, 2016 · Viewed 34.3k times · Source

I am making an android app with a few fragments. In one of these fragments, I have a toolbar with a back arrow as an image button.
In the XML File, I have the "app:srcCompat" attribute, but I get an error when using this attribute saying this: "To use VectorDrawableCompat, you need to set 'android.defaultConfig.vectorDrawables.useSupportLibrary = true'

Answer

Farbod Salamat-Zadeh picture Farbod Salamat-Zadeh · Dec 19, 2016

In your module build.gradle file, you need to add this line:

apply plugin: 'com.android.application'

android {
    ...

    defaultConfig {
        ...

        vectorDrawables.useSupportLibrary = true // This line here
    }
    ...
}

...