Resource not found Exception for vector drawables

旧城冷巷雨未停 提交于 2020-01-14 07:25:06

问题


I am going to run my app on some devices its crashes as logs below:

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) 

As resource not found in AppCompat library something. But I already added all required things in Build.gradle. Please have a ref:

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'

Please suggests any solution for the same.

Thanks in advance.


回答1:


You need to add abc_vector_test.xml in the drawable folder.

Updated:

You need to use it in AppCompat (activity etc) and moreover more imageView use this tag

app:srcCompat=

instead of

android:src=

hope it solves the problem.




回答2:


Have you tried moving the XML drawables to the drawable/ folder? That worked for me.

VectorDrawableCompat Resources$NotFoundException on KitKat and below

Solved: Android Resources$NotFoundException Crash Report




回答3:


I just had the same problem in Visual Studio / Xamarin and switching off:

  • Use shared runtime
  • use fast deployment
  • use incremental Android packaging system

in the app project options helped in my case.




回答4:


Not sure this is the same issue, but the symptom was the same. I was receiving the error

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

When the application was starting, following the stack trace though, it was actually being caused due to a in the XML file itself. Down a few caused bys showed that there was an error in parsing the XML file on the older Android versions.

The resolution in my case I had to do the following this: 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=""/>

This allowed the Splash layout/style/windowBackground to show as "expected" on devices ranging in more versions.



来源:https://stackoverflow.com/questions/41462731/resource-not-found-exception-for-vector-drawables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!