找不到资源向量drawables的例外

时间:2017-01-04 11:29:19

标签: android android-appcompat

我打算在某些设备上运行我的应用程序崩溃,如下所示:

01-04 16:54:02.206 7466-7466/com.lawnmowers E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lawnmowers, PID: 7466
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lawnmowers/com.lawnmowers.MapActivityNew}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f02004f
at android.content.res.Resources.loadDrawable(Resources.java:2099)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:182)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:717)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:187)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77)
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at com.lawnmowers.MapActivityNew.onCreate(MapActivityNew.java:89)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5086) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
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:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2095)
at android.content.res.Resources.getDrawable(Resources.java:700) 
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:346) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:182) 
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:717) 
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:187) 
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:77) 
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:127) 
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:147) 
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:27) 
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:50) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201) 
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:181) 
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:521)    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71) 
at com.lawnmowers.MapActivityNew.onCreate(MapActivityNew.java:89) 
at android.app.Activity.performCreate(Activity.java:5248) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257) 
at android.app.ActivityThread.access$800(ActivityThread.java:139) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5086) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 

由于资源在AppCompat库中找不到。但我已经在 Build.gradle 中添加了所有必需的内容。请有一个参考:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 24
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.lawnmowers"
        minSdkVersion 15
        multiDexEnabled true
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        incremental = true;
        preDexLibraries = false
        javaMaxHeapSize "4g" // 2g should be also OK
    }

}
repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.1'
    compile 'com.android.support:design:24.2.0'
    compile 'com.google.android.gms:play-services:10.0.0'
    compile 'com.android.support:support-v4:24.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
}
apply plugin: 'com.google.gms.google-services'

请为此建议任何解决方案。

提前致谢。

5 个答案:

答案 0 :(得分:0)

您需要在drawable文件夹中添加abc_vector_test.xml。

<强>更新

您需要在AppCompat(活动等)中使用它,而且更多imageView使用此标记

app:srcCompat=

而不是

android:src=

希望它能解决问题。

答案 1 :(得分:0)

您是否尝试将XML drawables移动到drawable /文件夹?这对我有用。

VectorDrawableCompat Resources$NotFoundException on KitKat and below

Solved: Android Resources$NotFoundException Crash Report

答案 2 :(得分:0)

我在Visual Studio / Xamarin中遇到了同样的问题,然后关闭了:

  • 使用共享的运行时
  • 使用快速部署
  • 使用增量Android打包系统
在应用程序项目选项中

就我而言有帮助。

答案 3 :(得分:0)

不确定这是相同的问题,但是症状是相同的。我收到错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.standardbredmobileapp/com.standardbredmobileapp.SplashScreen}: android.content.res.Resources$NotFoundException: File res/drawable/ic_splash_shapes.xml from drawable resource ID #0x7f02004f

启动应用程序时,尽管遵循堆栈跟踪,但实际上是由于XML文件本身中的引起的。向下的几个caused by表示在较旧的Android版本上解析XML文件时出错。

就我而言,该解决方案必须执行以下操作:VectorDrawable: Invalid drawable tag gradient

/drawable/ic_splash_shapes.xml 
Contains a <shape> solid with background

/drawable-v24/ic_splash_shapes.xml
Contains the original <gradient> with <item android:offset=""/>

这使Splash布局/样式/ windowBackground在更多版本的设备上显示为“预期”。

答案 4 :(得分:0)

如果此错误发生在21、22左右的android API级别上,则使用png代替矢量可以解决您的问题。 它为我解决了。