在 Android App Bundle 中添加 SwitchCompat 后,资源未找到错误 res/drawable/abc_switch_thumb_material.xml
Posted
技术标签:
【中文标题】在 Android App Bundle 中添加 SwitchCompat 后,资源未找到错误 res/drawable/abc_switch_thumb_material.xml【英文标题】:Resource Not Found error res/drawable/abc_switch_thumb_material.xml after adding SwitchCompat in Android App Bundle 【发布时间】:2018-12-16 02:46:00 【问题描述】:我知道这个问题已经被问过好几次了,我已经阅读了所有内容并匹配了所有依赖项,因此它们具有相同的版本,但是这个错误只是在添加 Switch Compat 后才开始发生,因为你也可以通过崩溃看到按面料报告。此错误并非在所有设备上发生,而是在崩溃报告中发生在某些设备上,而且它没有针对此崩溃的特定 android。由于 Android App Bundle,我正在使用 android 的 beta 版本,而这件事不会发生在 Apk 的非捆绑包中。
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfocom.App/com.App: android.view.InflateException: Binary XML file line #100: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3190)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by android.view.InflateException: Binary XML file line #100: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by android.view.InflateException: Binary XML file line #3: Error inflating class android.support.v7.widget.SwitchCompat
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.v7.view.menu.j.a(Unknown Source)
at android.support.v7.view.menu.j.setActionView(Unknown Source)
at android.support.v7.view.g$b.a(Unknown Source)
at android.support.v7.view.g$b.b(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.inflate(Unknown Source)
at android.support.design.widget.NavigationView.a(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.v7.view.menu.j.a(Unknown Source)
at android.support.v7.view.menu.j.setActionView(Unknown Source)
at android.support.v7.view.g$b.a(Unknown Source)
at android.support.v7.view.g$b.b(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.inflate(Unknown Source)
at android.support.design.widget.NavigationView.a(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.MainActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by android.content.res.Resources$NotFoundException: File res/drawable/abc_switch_thumb_material.xml from drawable resource ID #0x7f080048
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3985)
at android.content.res.Resources.loadDrawable(Resources.java:3853)
at android.content.res.Resources.getDrawable(Resources.java:1949)
at android.content.Context.getDrawable(Context.java:409)
at android.support.v4.a.a.a(Unknown Source)
at android.support.v7.widget.l.a(Unknown Source)
at android.support.v7.widget.l.a(Unknown Source)
at android.support.v7.c.a.b.b(Unknown Source)
at android.support.v7.widget.bm.a(Unknown Source)
at android.support.v7.widget.SwitchCompat.<init>(Unknown Source)
at android.support.v7.widget.SwitchCompat.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.v7.view.menu.j.a(Unknown Source)
at android.support.v7.view.menu.j.setActionView(Unknown Source)
at android.support.v7.view.g$b.a(Unknown Source)
at android.support.v7.view.g$b.b(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.inflate(Unknown Source)
at android.support.design.widget.NavigationView.a(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f080012
at android.content.res.Resources.getResourceName(Resources.java:3455)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3941)
at android.content.res.Resources.loadDrawable(Resources.java:3853)
at android.content.res.TypedArray.getDrawable(TypedArray.java:776)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:182)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:127)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3969)
at android.content.res.Resources.loadDrawable(Resources.java:3853)
at android.content.res.Resources.getDrawable(Resources.java:1949)
at android.content.Context.getDrawable(Context.java:409)
at android.support.v4.a.a.a(Unknown Source)
at android.support.v7.widget.l.a(Unknown Source)
at android.support.v7.widget.l.a(Unknown Source)
at android.support.v7.c.a.b.b(Unknown Source)
at android.support.v7.widget.bm.a(Unknown Source)
at android.support.v7.widget.SwitchCompat.<init>(Unknown Source)
at android.support.v7.widget.SwitchCompat.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.support.v7.view.menu.j.a(Unknown Source)
at android.support.v7.view.menu.j.setActionView(Unknown Source)
at android.support.v7.view.g$b.a(Unknown Source)
at android.support.v7.view.g$b.b(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.a(Unknown Source)
at android.support.v7.view.g.inflate(Unknown Source)
at android.support.design.widget.NavigationView.a(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at android.support.design.widget.NavigationView.<init>(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.l.b(Unknown Source)
at android.support.v7.app.e.setContentView(Unknown Source)
at com.App.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6575)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3143)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3300)
at android.app.ActivityThread.access$1000(ActivityThread.java:211)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1705)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6946)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
这是我的 build.gradle 依赖:-
dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
exclude group: 'com.android.support', module: 'support-annotations'
)
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.hotchemi:android-rate:1.0.1'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar')
transitive = true;
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
implementation 'petrov.kristiyan:colorpicker-library:1.1.8'
【问题讨论】:
我不知道这是否是原因,但在从 v7 支持库调用 v4 支持库后,您的基本错误 (ResourceNotFoundException
) 似乎都出现了。如果您删除 support-v4:27.1.1
依赖项,它还会构建吗? abc_switch_thumb_material.xml 在 v7 appcompat 支持库中。
是的,你是对的,它可以在没有 support-v4:27.1.1 的情况下完美构建和运行,这是我注意到的事情,有什么意见可以解决吗?
如果它可以构建并运行,那么解决方案是否消除了这种依赖关系? (是否还有其他原因需要 v4 支持库?)
我不认为这会解决问题,因为支持设计库已经包含 v4 库,请参阅 imgur.com/a/V8KD6y2 并且我的代码广泛使用 v4 支持库,谢谢
我当时很困惑,“它在没有 support-v4:27.1.1 的情况下完美构建和运行”是什么意思?我在这里错过了什么?
【参考方案1】:
根据您的错误消息,基本错误 (ResourceNotFoundException
) 在从 v7 支持库调用 v4 支持库后出现,在该库中找不到 abc_switch_thumb_material.xml
(位于 v7 库中)。
如果可能,从 gradle 文件中删除对 com.android.support:support-v4:27.1.1
的依赖。
【讨论】:
我在没有 support-v4 依赖的情况下遇到了这个问题,还有什么其他原因?以上是关于在 Android App Bundle 中添加 SwitchCompat 后,资源未找到错误 res/drawable/abc_switch_thumb_material.xml的主要内容,如果未能解决你的问题,请参考以下文章
使用Android App Bundle如何在系统语言更改时让系统下载新语言
成为 Android App Bundle 专家 | MAD Skills
如何使用 Android App Bundle 测试在舞台环境中运行的应用?