Reputation: 7060
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)
Upvotes: 16
Views: 10689
Reputation: 9812
If it is not working just for Pre-Lollipop, add this in your Activity
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Upvotes: 3
Reputation: 539
I found a rather interesting workaround to this. If you set the background to a drawable file that contains the xml drawable then the exception/crash goes away.
So create a drawable file that has the following:
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/your_image_here.xml" />
</selector>
and put the name of this drawable file as the background...
Upvotes: 5
Reputation: 276
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.
Upvotes: 26