Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17<vector> tag requires viewportWidth > 0
Asked Answered
S

31

87

I try to update my Support Library up to 23.2.0 and face this error:

Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:535)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:472)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:436)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:829)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:303)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

And

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chotot.vn.dev/com.chotot.vn.v2.activities.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v7.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:2091)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:897)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
at android.content.res.Resources.loadDrawable(Resources.java:2087)
at android.content.res.Resources.getDrawable(Resources.java:695)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.chotot.vn.v2.activities.MainActivity.onCreate(MainActivity.java:121)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

My activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/f_actionbar"
        android:name="com.chotot.vn.fragments.ActionBarFragment"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/main_tool_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentTop="true"
        android:background="@color/action_bar_bg">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include
                android:id="@+id/main_action_bar_layout"
                layout="@layout/layout_actionbar_custom_search"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top" />

            <LinearLayout
                android:id="@+id/main_action_bar_layout_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/main_action_bar_layout"
                android:orientation="vertical" />
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>

    <FrameLayout
        android:id="@+id/layout_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/main_tool_bar" />

</RelativeLayout>

How can I fix it?

Superimpose answered 25/2, 2016 at 8:53 Comment(8)
android-developers.blogspot.cz/2016/02/…Vocable
Can you please paste your vector drawable file?Porche
I am starting to give up android development as a &**&#$ whole! Can't believe I've been wasting a lot of my life as an individual person upgrading to one new SDK version to fix the bug they introduce on the previous version and now this! ARRGGGGHHH!Diatessaron
@NeonWarge easy man you had answers below.Superimpose
I settled for API v23.1.0 :PDiatessaron
having same problem in 24.0.0 if someone have tips about it, please share it, I really tried every thing.Hudspeth
@NeonWarge ... I've been around the block a few times now. These answers don't do anything for me. Am sure starting to feel painJeri
https://mcmap.net/q/146147/-resources-notfoundexception-file-res-drawable-abc_ic_ab_back_material-xmlDarlenedarline
P
54

Use this code in your build.gradle file

    //for Gradle Plugin 2.0+  
 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

If you are using Gradle 1.5 you’ll instead use

defaultConfig {
        generatedDensities = []
    }

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

I think may be they are using vector draw-able compact underneath in other lib.found here

Pique answered 25/2, 2016 at 10:31 Comment(17)
their other bugs also present.My card view height and width are getting expanded after new support lib.So i will wait for next version with bug fixes.Pique
For expanded layouts, try using wrap_content in your RecyclerView item layouts parent View. Using Match_parent was working before but not anymore.Nonrestrictive
@MAY3AM sorry not tried on Eclipse.Thought eclipse is outdated why are u using it.Pique
What finally solved my problem was @wonglik's answer, to set: buildToolsVersion "23.0.2".Mord
i am glad it did...:)Pique
Remember to use app:srcCompat instead of android:src in the xml to use the vector drawables on < 21 devices.Promethean
this dosn't work for me. my configuration is as below: buildToolsVersion "23.0.2" ; classpath 'com.android.tools.build:gradle:2.0.0-beta6' ; defaultConfig { vectorDrawables.useSupportLibrary = true}Trichromatic
This solution does not work for me. Could not find property 'vectorDrawables' on ProductFlavor_DecoratedVerne
@Verne that's because your gradle plugin is version 1.3.x instead of 1.5.0 or laterNeb
@MAY3AM You can use this project with Eclipse (github.com/dandar3/android-support-vector-drawable). See all the details in the references links.Rustler
What did he means with "I think may be they are using vector draw-able compact underneath in other lib.found here", should I import something else than com.android.support:appcompat ?Hudspeth
@Mord Thank you soo much; after hours of digging and digging I finally found you comment - and it worked! You are a life saver!Barbecue
Replace android:src with app:srcCompat in your xml layouts. Does it work?Wofford
I'm using buildToolsVersion "25.0.2" and still getting the issue. I have added vectorDrawables.useSupportLibrary = true as well. What am I missing?Dogcart
@TusharGogna have you got the solution for this..?Burning
@NarenderReddy yes, by using app:srcCompat for imageview and imagebuttonDogcart
Hi friends, i face the same problem in my case while raising this error on play the video in videoview, i already tired the all comments answer in this page but didnt get the solution, The error was Exception while inflating <animated-vector> java.lang.IllegalArgumentException: no valueFrom or no valueTo , please help me friends, i really dntknow abt this error..i cannot ply video please help me friends.Anglia
U
27

You can also upgrade to 23.4.0

dependencies {
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
}

and use a flag to manually enable this functionality:

static
{
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

inside the activity that uses the vectors.

Source: Age of the vectors

Uird answered 15/5, 2016 at 14:59 Comment(2)
the static call inside some base activity will fix the problem for all developers which are struggling with vectorDrawables.useSupportLibrary = true , so +1 for this answer.Abnaki
Oh, ♫ it's a kind of magic ♫. I am using com.android.support:appcompat-v7:25.3.1 running the app in API 19. Default config is vectorDrawables.useSupportLibrary = true but it was crashing when setting ImageSwitcher drawable with a vector. Finally with this static statement, I am able to setImageResource with the vector drawable. It seems that Android SDK is both amazing and imature.Pasol
E
26

Please remove the appcompat gradle( compile "com.android.support:appcompat-v7:23.2.0") and replace with support design (compile 'com.android.support:design:23.1.1') this will solve the problem

Electrolysis answered 2/3, 2016 at 8:6 Comment(2)
Are these changes also to be done with 23.1.1 defaultConfig { generatedDensities = [] } // This is handled for you by the 2.0+ Gradle Plugin aaptOptions { additionalParameters "--no-version-vectors" }Yiyid
but what if you want to use the latest appcompact library??Pique
B
23

On pre-lollipop devices you need to create selector to use VectorDrawable elsewhere from ImageView

app:srcCompat="@drawable/your_vector_drawable"

Selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/your_vector_drawable" />

</selector>

Then you can pass this selector, e.g. for TextView drawableLeft/drawableRight in xml

<TextView
        android:gravity="center_vertical"
        android:drawableLeft="@drawable/selector_your_vector_drawable"
        android:drawableStart="@drawable/selector_your_vector_drawable"
        android:drawableRight="@drawable/selector_your_vector_drawable"
        android:drawableEnd="@drawable/selector_your_vector_drawable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/your_string" />
Bananas answered 5/3, 2016 at 12:46 Comment(4)
Regardless of the versions in build.gradle, this solution will workProximal
I have vectorDrawables.useSupportLibrary = true in app build.gradle and I use compileSdkVersion 25 and buildToolsVersion "25.0.0" and dependency libraries revisions 25.0.0 but not helped useSupportLibrary, this is best solution thank you @n1ck!!!Pragmatism
This solution not breaks on support library 25.00 and 24 too, I tested on Android 4.2.2 tablet (not support google play) and this solutions works like charm!Pragmatism
This works as of today [buildtools 25+] - nothing else works for android:drawable attribs in xml:s referencing vector drawables. It's either this or setting the background drawable programatically. Wth!Roundworm
M
22

Instead of ContextCompat.getDrawable , just use AppCompatDrawableManager.get().getDrawable .

This should work on versions higher than 23.+

Milka answered 25/8, 2016 at 10:41 Comment(4)
I'm trying to use vector for custom view. This works for me. But only directly call AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.drawable_xyz); by code. Not sure how it works if declared by xml.Gipson
this change by itself fixed the problem for me. thank you.Gunmaker
This fixed ma problem too. Thanks mate !Reinaldo
Also you can use: AppCompatResources.getDrawable(getContext(), R.drawable.drawable_xyz);Cohen
S
20

Using:

compileSdkVersion 24
buildToolsVersion '24.0.1'

I crashed at run time until I removed the line

  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }

from my application guild.gradle

This appears to confuse the newer version of the SDK

Hope this saves someone else headaches

Selfsealing answered 8/9, 2016 at 17:49 Comment(3)
This helps to me.Ernestineernesto
Removing the ectorDrawables.useSupportLibrary stopped the crashes on my 4.4.2 device.Tailgate
Wow it's really works! But why there is an annoying lint error with app:srcCompat To use VectorDrawableCompat, you need to set android.defaultConfig.vectorDrawable.useSupportLibrary = true.? It's very confusing!Fifi
A
12

I fixed this problem by replacing

dependencies {

compile 'com.android.support:appcompat-v7:23.2.0'

compile 'com.android.support:design:23.2.0'
}

with

dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'

compile 'com.android.support:design:23.0.1'
}
Ative answered 14/3, 2016 at 12:40 Comment(0)
A
10

A mix of few of the above solutions worked for me. Here is what I did -

Change gradle version from 1.3.0 to 1.5.0 in build.gradle of project like this

classpath 'com.android.tools.build:gradle:1.5.0'

Update below things in build.gradle of app

buildToolsVersion "23.0.2"

Updated Module dependencies from 23.2.0 to 23.4.0:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-vector-drawable:23.4.0'
compile 'com.android.support:animated-vector-drawable:23.4.0'

Now depending upon the gradle version you're using, use either of the following two snippets. Since I am using gradle 1.5.0, I used this -

defaultConfig {
            generatedDensities = []
            }

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

But if you are using Gradle 2.1.0 use this instead

       defaultConfig {  
         vectorDrawables.useSupportLibrary = true  
         }

And then you're good to go. I tested it both in xml as well as programmatically. In xml file, I used this in my ImageView -

app:srcCompat="@drawable/anim_droid"
// where droid_anim is an animated-vector file containing set of animations to animate different paths of the SVG file

And to do it programmatically, I used this -

    imageView.setImageResource(R.drawable.anim_droid);
    Drawable drawable = imageView.getDrawable();
    if (drawable instanceof Animatable) {
      ((Animatable) drawable).start();
    }

Hope it helps! Cheers :)

Ameline answered 26/5, 2016 at 12:35 Comment(0)
N
9

Had the same problem. For me actually upgrading build Tools version helped :

buildToolsVersion "23.0.2"
Nunley answered 29/2, 2016 at 18:5 Comment(0)
E
9

Face the crash problem on api 19 when update to 23.2.0. I solved this problem by update the version to 23.2.1.(The latest version when answer this question. Try to update to latest, maybe google has been fixed it)

compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support:23.2.1'.
Ethban answered 12/3, 2016 at 9:3 Comment(2)
Why do you need to compile the whole 'com.android.support:support:23.2.1'?Avigation
The latest for the moment compile 'com.android.support:support-v4:23.3.0' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0'Overturf
I
7

Make sure you use the latest buildToolsVersion as well (Download from SDK manager if needed).

Sample Gradle:

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        ...
        vectorDrawables.useSupportLibrary = true
    }
    dependencies {
        ...
        compile 'com.android.support:appcompat-v7:24.0.0'
        ...
    }
}
Idealistic answered 1/7, 2016 at 12:24 Comment(2)
buildToolsVersion "24.0.0" save my day :)Bier
This is correct answer for who is trying to update to compile sdk 24 but was still getting error on 4.x devices.Pontone
A
4

In Gradle (gradle:2.1.0):

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

In layout:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/you_vector_drawable"/>
Avigdor answered 24/5, 2016 at 18:19 Comment(0)
T
3

I had this problem, but updating to the versions build:grade:

classpath 'com.android.tools.build:gradle:1.5.0'

And:

buildToolsVersion "23.0.2"

Success!

Trousseau answered 13/3, 2016 at 16:55 Comment(0)
W
3

Replace android:src with app:srcCompat

Wofford answered 23/9, 2016 at 1:31 Comment(0)
I
2

I was supprised by this exact same problem when I built a new version of my app. My dependency to appcompact was set to auto update.

compile 'com.android.support:appcompat-v7:23+'

So as soon as a new version is available (in this case version 23.2.0) it will replace the old one you were building with.

So you can either switch back to the previous version of the appcompat library (Quick fix):

compile 'com.android.support:appcompat-v7:23.1.1'

Or keep the current library version and use Ajinkya's answer as explained by google in version 23.2.0 release note. If you opt for the later, don't forget to update your gradle build tool to version 1.5.0 or you couldn't use the new parameters like generatedDensities:

classpath 'com.android.tools.build:gradle:1.5.0'
Irbm answered 2/3, 2016 at 13:41 Comment(0)
L
2

Faced the same issue, this solution fixed it.

In your class just do

public class YourClass extends xxx {
    static {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    }
    ...
}

and also add this in your gradle file if not yet.

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}
Leucas answered 27/1, 2018 at 10:43 Comment(0)
M
1

I have fixed it by setting..

compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1' and buildToolsVersion '24.0.0'
Multiplechoice answered 23/7, 2016 at 6:20 Comment(1)
Tried this but didn't work for me... Using Android-IDESansen
A
1

I met this problem too, what I did: change

compileSdkVersion 24
buildToolsVersion "22.0.1"

to

compileSdkVersion 24
buildToolsVersion "24.0.1"
Autogenesis answered 13/1, 2017 at 8:47 Comment(0)
V
1

Insert to build.gradle(Module: app):

android {  
  defaultConfig {  
    vectorDrawables.useSupportLibrary = true  
  }  
}

dependencies {
    implementation 'com.android.support:appcompat-v7:26.1.0'
}

After, use the code below, in you AppActivity:

 AppCompatResources.getDrawable(getContext(), R.drawable.ic_your);

Where available use the app:srcCompat instead android:src and android:background, in XML resource file

Victualler answered 19/1, 2018 at 9:56 Comment(0)
P
0

I had this problem, but updating to the versions below fixed it for me:

classpath 'com.android.tools.build:gradle:1.5.0'

And:

buildToolsVersion "23.0.2"

Module dependencies:

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'

compile 'com.google.android.gms:play-services:8.4.0'
Promisee answered 7/3, 2016 at 23:59 Comment(0)
S
0

I fixed the problem by replacing

compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'

with

compile 'com.android.support:appcompat-v7:23.0.2'
compile 'com.android.support:support-v4:23.0.2'
Shambles answered 4/5, 2016 at 2:7 Comment(0)
T
0

I got this same error in Android Studio 2.2 after I updated my Gradle dependencies to the latest versions but forgot to update the buildToolsVersion of my project.

I changed:

compile 'com.android.support:appcompat-v7:22.2.1'

to:

compile 'com.android.support:appcompat-v7:24.2.1'

While buildToolsVersion remained at "22.0.1" like so:

buildToolsVersion "22.0.1"

So all I did was to update the buildToolsVersion to 24 like so:

buildToolsVersion "24"

since it has previously been download with SDK Manager. So check the latest buildToolsVersion from SDK Manager and see if it matches the dependencies version.

Hope this helps someone.

Topee answered 28/9, 2016 at 13:54 Comment(0)
J
0

For me what worked... was removing the 's' from 'https' in the namespace declaration of my xml vector drawable.

That XML came from Google Android documentation itself. You can see in the screenshot that the xmlns is 'http' but in the copy-pastable version below, it's 'https.'

This will stop the rendering errors in the Vector Asset viewer, but you still wont see anything, for reasons I don't get. It's supposed to look like a wrench.

If you right-click the drawables folder and "New --> Vector Asset" you get an android icon asset that works.

<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="M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"/>

Both my design and my appcompat-v7 use 23.2.1, and buildToolsVersion 23.0.2.

This just in. The wrench generated by the 'material icons' interface file --> new --> vector asset --> material icon (then click the icon and select wrench) is:

<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="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z"/>
</vector>

This online utility did okay by me. Use Chrome. It converts SVG to android vector drawables.

Jeri answered 21/12, 2016 at 17:38 Comment(0)
F
0

problem was :

/VdcInflateDelegate: Exception while inflating <vector>

solution:

changed compileSdkVersion 23 buildToolsVersion "23.0.2" to compileSdkVersion 24 buildToolsVersion "24.0.2"

solution code:

compileSdkVersion 24
buildToolsVersion '24.0.1'

using this above code I solved the problem

Filemon answered 16/3, 2017 at 7:4 Comment(0)
M
0

Just add the following dependancy in your build.gradle. this will fix your problem. I'm using 25.0.2 buildToolsVersion.

compile 'com.android.support:support-vector-drawable:25.3.0'

Mcgregor answered 27/3, 2017 at 10:1 Comment(0)
V
0

I changed the FragmentActivity to AppCompatActivity, the problem is solved. My environment is:

compileSdkVersion = 25
buildToolsVersion = "25.0.0"
supportVersion = "25.2.0"
Voltmeter answered 31/3, 2017 at 2:57 Comment(0)
P
0

In my case this solution worked:

Use

android:theme="@style/TextLabelWhite"

just like in your xml. Change style parent to your AppTheme style, like:

<style name="TextLabelWhite" parent="AppTheme">
Pervert answered 13/5, 2017 at 6:45 Comment(0)
M
0

Even though I have support of vector enabled in my gradle and have the latest version of gradle, build tools, support library and Android studio, I still got the error.

Here a fix for my case:

AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.drawable_xyz);

to supress the lint warning add this @SuppressLint("RestrictedApi")

Maidservant answered 9/7, 2017 at 18:42 Comment(0)
K
0

try to use : compile 'com.android.support:design:23.1.1'

instead of: compile "com.android.support:appcompat-v7:23.2.0"

Kail answered 3/11, 2017 at 10:3 Comment(0)
M
0

Also Observed on buildToolsVersion '26.0.2'

Downgrading to buildToolsVersion '25.0.3' worked.

For buildToolsVersion '26.0.2' : Try AppCompat for Widgets Example : TextView -> android.support.v7.widget.AppCompatTextView (For older Android Version support) Also observed on lower end devices when the device is unable to inflate drawables due to memory shortage.(Even though the drawable exists in your res->drawable dir) : Try changing your drawable with less complex ones.

Messer answered 10/1, 2018 at 13:15 Comment(0)
T
0

My Application crashed on API<17 because of vector drawables in TextView compound drawable. My solution was to stop using Compound Drawables with Text Views and use ImageView instead. As google recommends:

  • vectorDrawables.useSupportLibrary = true
  • Use app:SrcCompat attribute for vector drawables.
  • Use setImageResource() in code to set icons.
Tetrahedron answered 7/3, 2018 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.