Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<animated-vector> requires API level 21 (current min is 15)

Tags:

android

It is mentioned [here][1] that the new support library now supports animated vectors, which was previously only supported in API 21+. I upgraded my support library to the latest version.

But Android Studio still gives me a warning: animated-vector requires API level 21 (current min is 15).

I did the followings:

I added the following codes to build.gradle:

defaultConfig {
    generatedDensities = []

}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}

So now my build.gradle file looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.mahdi.askhow"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    generatedDensities = []

}
// This is handled for you by the 2.0+ Gradle Plugin
aaptOptions {
    additionalParameters "--no-version-vectors"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.wang.avi:library:1.0.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile project(':phoenix')
    compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.3'

}

My animated drawable:

<?xml version="1.0" encoding="utf-8"?>
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/vector_upvote">

    <target
        android:name="rotationGroup"
        android:animation="@anim/rotate_a_to_b" />


    <target
        android:name="left_arrow"
        android:animation="@animator/animator_checkmark" />
</animated-vector>

On the first line of the animated drawable, it says: animated-vector requires API level 21 (current min is 15).

So what is wrong?

  [1]: http://android-developers.blogspot.com/2016/02/android-support-library-232.html
like image 872
SMahdiS Avatar asked Feb 25 '16 20:02

SMahdiS


1 Answers

Ok. I tested this. IT WORKS! I created animated vector drawable and added this to layout:

<ImageView
    android:id="@+id/animated"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    app:srcCompat="@drawable/animated" />

And this to code:

ImageView animatedView = (ImageView) findViewById(R.id.animated);
Drawable animation = animatedView.getDrawable();
if (animation instanceof Animatable) {
    ((Animatable) animation).start();
}

Android studio show me this drawable in preview but app crashed on start (Android 4.0 phone)

Then I replaced android:src by app:srcCompat and preview became broken. But this app started on Android 4.0 phone and animation works.

Conclusion: support library works. Android studio (1.5.1) not ready yet.

like image 61
Alexandr Shutko Avatar answered Oct 21 '22 11:10

Alexandr Shutko