XmlPullParserException: invalid drawable tag vector

Malwinder Singh picture Malwinder Singh · Dec 29, 2015 · Viewed 9.9k times · Source

I am using NDK support and getting this error:

Gradle:

Distribution: gradle-2.5-all

Build tool: gradle-experimental:0.2.1

XML:

    <vector android:height="24dp" android:viewportHeight="125.0"
android:viewportWidth="100.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M97.01,-2.98,-3C47.02,95.35"/>
</vector>

Warning:

vector requires API level 21 (current min is 13) or building with Android Gradle plugin 1.4 or higher

Exception:

  FATAL EXCEPTION: main
 android.content.res.Resources$NotFoundException: File res/drawable/accelerometer.xml from drawable resource ID #0x7f020045
 at android.content.res.Resources.loadDrawable(Resources.java:2842)
 at android.content.res.Resources.getDrawable(Resources.java:1521)

...
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
 at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
 at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)

Answer

Tyler Howes picture Tyler Howes · Apr 12, 2017

On pre-Lollipop devices you need to use VectorDrawableCompat to get your vector from resources.

 someVectorDrawable = VectorDrawableCompat.create(context.getResources(), R.drawable.[some res id], null);

Then you can set your ImageView's background.