Vector compatibility through AppCompat

suggest change

A few pre-requisites in the build.gradle for vectors to work all the way down to API 7 for VectorDrawables and API 13 for AnimatedVectorDrawables (with some caveats currently):

android {
    // Build Tools has to be 24+
    buildToolsVersion '24.0.0'

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        // Gradle plugin 1.5 workaround. Plugin 2.0+ keeps vectors via useSupportLibrary.
        generatedDensities = []
    }
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:24.1.1'
}

aaptOptions belongs on the android block. Nesting it in defaultConfig is not valid Gradle. generatedDensities and --no-version-vectors are the Gradle 1.5 workaround. With plugin 2.0 or newer, vectorDrawables.useSupportLibrary = true is the setting that keeps the vectors as vectors.

In your layout.xml:

<ImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/vector_drawable"
    android:contentDescription="@null" />

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents