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?

mr.icetea
  • 2,607
  • 3
  • 24
  • 42

31 Answers31

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

Ajinkya
  • 2,286
  • 3
  • 18
  • 25
  • 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. – Ajinkya Feb 25 '16 at 10:33
  • For expanded layouts, try using wrap_content in your RecyclerView item layouts parent View. Using Match_parent was working before but not anymore. – Oğuzhan Döngül Feb 25 '16 at 17:12
  • 7
    @MAY3AM sorry not tried on Eclipse.Thought eclipse is outdated why are u using it. – Ajinkya Mar 03 '16 at 04:22
  • 6
    What finally solved my problem was @wonglik's answer, to set: buildToolsVersion "23.0.2". – Sid Mar 04 '16 at 10:18
  • i am glad it did...:) – Ajinkya Mar 04 '16 at 10:37
  • 1
    Remember to use app:srcCompat instead of android:src in the xml to use the vector drawables on < 21 devices. – Timo Albert Mar 04 '16 at 16:35
  • 1
    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} – Allen Vork Mar 06 '16 at 09:20
  • 6
    This solution does not work for me. `Could not find property 'vectorDrawables' on ProductFlavor_Decorated` – Mulgard Mar 07 '16 at 09:48
  • @Mulgard that's because your gradle plugin is version 1.3.x instead of 1.5.0 or later – Gabor Apr 27 '16 at 21:06
  • @MAY3AM You can use this project with Eclipse (https://github.com/dandar3/android-support-vector-drawable). See all the details in the references links. – Dan Dar3 May 20 '16 at 03:19
  • 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` ? – wviana Jun 30 '16 at 13:18
  • @Sid Thank you soo much; after hours of digging and digging I finally found you comment - and it worked! You are a life saver! – Namnodorel Aug 04 '16 at 18:56
  • Replace android:src with app:srcCompat in your xml layouts. Does it work? – AnupamChugh Sep 23 '16 at 01:31
  • I'm using buildToolsVersion "25.0.2" and still getting the issue. I have added vectorDrawables.useSupportLibrary = true as well. What am I missing? – Tushar Gogna Feb 01 '17 at 06:41
  • @TusharGogna have you got the solution for this..? – Narender Reddy Feb 07 '17 at 09:56
  • @NarenderReddy yes, by using app:srcCompat for imageview and imagebutton – Tushar Gogna Feb 07 '17 at 11:05
  • 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 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. – Vijay Sep 04 '17 at 14:59
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

iCantSeeSharp
  • 3,880
  • 4
  • 42
  • 65
  • 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. – Stoycho Andreev Oct 12 '16 at 13:15
  • 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. – Junior Mayhé Jul 11 '17 at 21:12
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

sKhan
  • 9,694
  • 16
  • 55
  • 53
Abhilash
  • 500
  • 4
  • 13
  • 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" } – Ravi Mar 17 '16 at 05:22
  • 20
    but what if you want to use the latest appcompact library?? – Ajinkya Apr 19 '16 at 17:03
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" />
Nikita Axyonov
  • 1,314
  • 8
  • 18
  • Regardless of the versions in build.gradle, this solution will work – PsyGik Apr 19 '16 at 10:22
  • 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!!! – SBotirov Oct 21 '16 at 06:27
  • 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! – SBotirov Oct 21 '16 at 06:30
  • 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! – Pär Nils Amsen Mar 09 '17 at 16:15
22

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

This should work on versions higher than 23.+

Ivelius
  • 4,953
  • 7
  • 30
  • 54
  • 1
    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. – Robert Sep 06 '16 at 06:02
  • 1
    this change by itself fixed the problem for me. thank you. – albert c braun Oct 04 '16 at 04:52
  • 1
    This fixed ma problem too. Thanks mate ! – rana Dec 09 '16 at 03:06
  • 1
    Also you can use: ```AppCompatResources.getDrawable(getContext(), R.drawable.drawable_xyz);``` – Warcello Apr 07 '17 at 12:15
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

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Mark Z. Kumler
  • 231
  • 2
  • 4
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'
}
Abhijeet Mallick
  • 1,740
  • 2
  • 16
  • 21
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 :)

Shubhral
  • 334
  • 3
  • 15
9

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

buildToolsVersion "23.0.2"
wonglik
  • 1,043
  • 4
  • 18
  • 36
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'.
tiegeda
  • 121
  • 4
  • 1
    Why do you need to compile the whole `'com.android.support:support:23.2.1'`? – IgorGanapolsky Mar 29 '16 at 21:22
  • 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' – Alexandr Apr 18 '16 at 19:22
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'
        ...
    }
}
Much Overflow
  • 3,142
  • 1
  • 23
  • 40
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"/>
bitvale
  • 1,959
  • 1
  • 20
  • 27
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!

Ds Digital
  • 31
  • 2
3

Replace android:src with app:srcCompat

AnupamChugh
  • 1,779
  • 1
  • 25
  • 36
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'
Community
  • 1
  • 1
Gomino
  • 12,127
  • 4
  • 40
  • 49
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
}
Gomez NL
  • 912
  • 9
  • 12
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'
Rcc
  • 11
  • 1
1

I met this problem too, what I did: change

compileSdkVersion 24
buildToolsVersion "22.0.1"

to

compileSdkVersion 24
buildToolsVersion "24.0.1"
aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
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

amiron
  • 721
  • 9
  • 11
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'
T.Coutlakis
  • 2,436
  • 1
  • 19
  • 19
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'
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.

Cletus Ajibade
  • 1,550
  • 15
  • 14
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.

Jan Jansz
  • 630
  • 7
  • 13
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

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
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'

Nanda Gopal
  • 2,519
  • 1
  • 17
  • 25
0

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

compileSdkVersion = 25
buildToolsVersion = "25.0.0"
supportVersion = "25.2.0"
ttdevs
  • 101
  • 2
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">
Community
  • 1
  • 1
Ghasem
  • 14,455
  • 21
  • 138
  • 171
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")

Mohamed ALOUANE
  • 5,349
  • 6
  • 29
  • 60
0

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

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

Farid Savad
  • 163
  • 1
  • 11
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.

Sandeep PC
  • 797
  • 8
  • 12
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.
Khizhny Andrey
  • 161
  • 1
  • 5