将Android支持库更新到23.2.0导致错误:XmlPullParserException二进制XML文件行#17标记需要viewportWidth> 0

tvel 发布于 2019-08-15 android 最后更新 2019-08-15 14:00 151 浏览

我尝试将我的支持库更新至23.2.0,并且遇到此错误:

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)
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)
我的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>
我该如何解决它?
已邀请:

nut

赞同来自:

我有这个问题,但更新到以下版本为我修复了它:

classpath 'com.android.tools.build:gradle:1.5.0'
和:
buildToolsVersion "23.0.2"
模块依赖:
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'

eearum

赞同来自:

我通过替换修复了问题

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

qet

赞同来自:

当我构建我的应用程序的新版本时,我被这个完全相同的问题所困扰。我对appcompact的依赖设置为自动更新。

compile 'com.android.support:appcompat-v7:23+'
因此,只要有新版本(在本例中为版本23.2.0),它就会替换您正在构建的旧版本。 因此,您可以切换回以前版本的appcompat库(快速修复):
compile 'com.android.support:appcompat-v7:23.1.1'
或保留当前库版本并使用Ajinkya的答案,如google in version 23.2.0 release note所述。 如果您选择更晚的版本,请不要忘记将gradle构建工具更新到1.5.0版,否则您无法使用generatedDensities等新参数:
classpath 'com.android.tools.build:gradle:1.5.0'

nqui

赞同来自:

我将FragmentActivity更改为AppCompatActivity,问题解决了。我的环境是:

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

kquis

赞同来自:

有同样的问题。对我来说实际升级构建工具版有帮助:

buildToolsVersion "23.0.2"

ket

赞同来自:

只需在build.gradle中添加以下依赖项。这将解决您的问题。我正在使用25.0.2 buildToolsVersion。 编译'com.android.support:support-vector-drawable:25.3.0'

sit_et

赞同来自:

请删除appcompat gradle(     compile "com.android.support:appcompat-v7:23.2.0") 并用支持设计(compile 'com.android.support:design:23.1.1')替换,这将解决问题

mest

赞同来自:

在build.gradle文件中使用此代码

    //for Gradle Plugin 2.0+  
 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }
如果您使用的是Gradle 1.5,则可以使用
defaultConfig {
        generatedDensities = []
    }
// This is handled for you by the 2.0+ Gradle Plugin
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
我想可能是他们在其他lib.found here下使用矢量绘图紧凑

zrerum

赞同来自:

android:src替换为app:srcCompat

uanimi

赞同来自:

即使我支持在我的gradle中启用了vector并且拥有最新版本的gradle,构建工具,支持库和Android studio,我仍然遇到错误。 这是我案例的修复:

AppCompatDrawableManager.get().getDrawable(getContext(), R.drawable.drawable_xyz);
要压制lint警告,请添加此@SuppressLint("RestrictedApi")

uet

赞同来自:

我也遇到了这个问题,我做了什么: 更改

compileSdkVersion 24
buildToolsVersion "22.0.1"
compileSdkVersion 24
buildToolsVersion "24.0.1"

id_aut

赞同来自:

您也可以升级到23.4.0

dependencies {
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
}
并使用标志手动启用此功能:
static
{
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
在使用向量的活动内部。 资料来源:Age of the vectors

raut

赞同来自:

更新到23.2.0时面对api 19上的崩溃问题。 我通过将版本更新到23.2.1解决了这个问题。(回答这个问题时的最新版本。尝试更新到最新版本,也许google已经修复了)

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

et_et

赞同来自:

尝试使用: 编译'com.android.support:design:23.1.1' 代替: 编译“com.android.support:appcompat-v7:23.2.0”

get

赞同来自:

而不是ContextCompat.getDrawable,只需使用AppCompatDrawableManager.get()。getDrawable。 这应该适用于高于23. +的版本

qodio

赞同来自:

在Gradle(gradle:2.1.0):

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}
在布局中:
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/you_vector_drawable"/>

qporro

赞同来自:

对我来说什么有用...是从我的xml矢量drawable的名称空间声明中的'https'中删除's'。 That XML came from Google Android documentation itself.你可以在屏幕截图中看到xmlns是'http',但在下面的copy-pastable版本中,它是'https'。 这将停止Vector Asset查看器中的渲染错误,但您仍然看不到任何内容,原因是我没有得到。它应该看起来像一把扳手。 如果您右键单击drawables文件夹和“新建 - >矢量资产”,您将获得一个有效的Android图标资产。

<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"/>
我的设计和appcompat-v7都使用23.2.1和buildToolsVersion 23.0.2。 这就是。由'材料图标'界面文件生成的扳手 - >新建 - >矢量资产 - >材料图标(然后单击图标并选择扳手)是:
<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对我没问题。使用Chrome。它将SVG转换为android vector drawables。

ererum

赞同来自:

上述几种解决方案的混合对我有用。这是我做的 - 在此项目的build.gradle中将gradle版本从1.3.0更改为1.5.0

classpath 'com.android.tools.build:gradle:1.5.0'
在应用的build.gradle中更新以下内容
buildToolsVersion "23.0.2"
更新了从23.2.0到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'
现在,根据您使用的gradle版本,请使用以下两个代码段中的任何一个。 由于我使用的是gradle 1.5.0,我使用了这个 -
defaultConfig {
            generatedDensities = []
            }
aaptOptions {
        additionalParameters "--no-version-vectors"
        }
但是,如果您使用的是Gradle 2.1.0,请改用它
       defaultConfig {  
         vectorDrawables.useSupportLibrary = true  
         }
然后你很高兴去。我用xml和编程方式测试了它。在xml文件中,我在我的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
为了以编程方式进行,我使用了这个 -
    imageView.setImageResource(R.drawable.anim_droid);
    Drawable drawable = imageView.getDrawable();
    if (drawable instanceof Animatable) {
      ((Animatable) drawable).start();
    }
希望能帮助到你!干杯:)

iaut

赞同来自:

我通过替换修复了这个问题

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

kalias

赞同来自:

我通过设置修复了它..

compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1' and buildToolsVersion '24.0.0'

verror

赞同来自:

我有这个问题,但更新到版本build:grade:

classpath 'com.android.tools.build:gradle:1.5.0'
和:
buildToolsVersion "23.0.2"
成功!

zet

赞同来自:

使用:

compileSdkVersion 24
buildToolsVersion '24.0.1'
我在运行时崩溃,直到我删除了线
  defaultConfig {
    vectorDrawables.useSupportLibrary = true
  }
从我的应用程序guild.gradle 这似乎会混淆较新版本的SDK 希望这可以节省别人的头痛

bmagni

赞同来自:

在我将Gradle依赖项更新为最新版本但忘记更新项目的buildToolsVersion之后,我在Android Studio 2.2中遇到了同样的错误。 我变了:

compile 'com.android.support:appcompat-v7:22.2.1'
至:
compile 'com.android.support:appcompat-v7:24.2.1'
虽然buildToolsVersion保持在"22.0.1",如下所示:
buildToolsVersion "22.0.1"
所以我所做的就是将buildToolsVersion更新为24,如下所示:
buildToolsVersion "24"
因为之前已经使用SDK Manager下载了。因此,请从SDK Manager中检查最新的buildToolsVersion,看它是否与依赖项版本匹配。 希望这有助于某人。

seaque

赞同来自:

在pre-lollipop设备上,您需要创建选择器以在ImageView的其他位置使用VectorDrawable

app:srcCompat="@drawable/your_vector_drawable"
选择:
<?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>
然后你可以传递这个选择器,例如对于TextView中的drawableLeft / drawableRight
<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" />

et_ea

赞同来自:

问题是:
/VdcInflateDelegate: Exception while inflating <vector>

溶液: 已更改compileSdkVersion 23 buildToolsVersion "23.0.2"compileSdkVersion 24 buildToolsVersion "24.0.2"

解决方案代码:
compileSdkVersion 24
buildToolsVersion '24.0.1'
使用上面的代码我解决了这个问题

csequi

赞同来自:

就我而言,this解决方案有效:

Use
android:theme="@style/TextLabelWhite"
just like in your xml. Change style parent to your AppTheme style, like:
<style name="TextLabelWhite" parent="AppTheme">

aad

赞同来自:

确保您也使用最新的buildToolsVersion(如果需要,从SDK管理器下载)。 示例Gradle:

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        ...
        vectorDrawables.useSupportLibrary = true
    }
    dependencies {
        ...
        compile 'com.android.support:appcompat-v7:24.0.0'
        ...
    }
}