Error Resources $ NotFoundException for ImageView with vector drawable on Android

1

I just received an ANR report in the Google Play Console of an app that a user has shown to me using my app.

android.content.res.Resources$NotFoundException: File res/drawable/ic_circular_way.xml from drawable resource ID #0x7f02006a. If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
...
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

I guess it means that I use drawables in the form of a vector.

In the gradle I have already defined the use of

defaultConfig {
   ...
   vectorDrawables.useSupportLibrary = true
   ...
}

That error comes from Android 4.4 (KitKat)

    
asked by Webserveis 16.01.2017 в 14:48
source

2 answers

1

Looking for the solution, I found this answer from SO

In the gradle define if 2.0 or higher is used

defaultConfig {
    ...
    vectorDrawables.useSupportLibrary = true
    ...
}

With the contribution of @Miguel Osorio and complementing Android Support Library (III) - VectorDrawables

If we use an earlier version

android {  
    defaultConfig {
        generatedDensities = []  
    }  

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

}  

In OnCreate of activities

AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

In case of using vector resources on the sides of a TextView using the property android:drawableLeft the vector should be included in a layer-list

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_location_on_black_12dp"/>
</layer-list>

and to use it:

android:drawableLeft="@drawable/ic_hackside_location_on_black"

Retrieved from answer SO

    
answered by 16.01.2017 / 15:10
source
1

Inside the build.gradle you must have:

android {

    defaultConfig {
        ...
        vectorDrawables.useSupportLibrary = true

    }

and when loading these graphics must be created first by VectorDrawableCompat.create() :

myImageView.setImageDrawable(VectorDrawableCompat.create(myImageView.getResorces(), R.drawable.ic_my_image, null));
    
answered by 16.01.2017 в 17:00