Update Android Support Library to 23.2.0 cause err

2019-01-02 20:29发布

问题:

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?

回答1:

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



回答2:

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



回答3:

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



回答4:

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" />


回答5:

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

This should work on versions higher than 23.+



回答6:

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



回答7:

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'
}


回答8:

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 :)



回答9:

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

buildToolsVersion "23.0.2"


回答10:

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'.


回答11:

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'
        ...
    }
}


回答12:

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"/>


回答13:

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!



回答14:

Replace android:src with app:srcCompat



回答15:

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'


回答16:

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
}


回答17:

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'


回答18:

I met this problem too, what I did: change

compileSdkVersion 24
buildToolsVersion "22.0.1"

to

compileSdkVersion 24
buildToolsVersion "24.0.1"


回答19:

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



回答20:

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'


回答21:

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'


回答22:

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.



回答23:

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.



回答24:

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



回答25:

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'



回答26:

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

compileSdkVersion = 25
buildToolsVersion = "25.0.0"
supportVersion = "25.2.0"


回答27:

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">


回答28:

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")



回答29:

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

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



回答30:

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.



标签: