Denis Steinman
Denis Steinman

Reputation: 7799

VectorDrawableCompat.create cannot create image from vector.xml on old devices

I used this code to support vector images on old devices:

VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());

But it doesn't work at this moment (I installed few updates for Android Studio 2.1.1)

My gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    dataBinding {
        enabled = true
    }

    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.android.support:support-annotations:23.4.0'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
}

Example of vector resource:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
</vector>

It prints errors:

android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/ic_insert_link_24.png from xml type xml resource ID #0x7f020062 at android.content.res.Resources.loadXmlResourceParser(Resources.java:3045) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2992) at android.content.res.Resources.getXml(Resources.java:1772) at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)

Does who know hot to fix this bug?
P.S. I know that ImageView and some else Views supports VectorDrawableCompat default but I need get Drawable to draw it on Canvas

Upvotes: 1

Views: 1385

Answers (1)

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20950

Look at the error should say something.

android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/ic_insert_link_24.png from xml type xml resource ID #0x7f020062

you are using ic_insert_link_24.png this should not present in drawable folder so this error is occure try to put it on the drawable folder and check it.

Upvotes: 1

Related Questions