consp1racy / android-support-preference

Android Preferences according to Material design specs
Apache License 2.0
331 stars 49 forks source link

InflateException Resources$NotFoundException #119

Open rubengees opened 5 years ago

rubengees commented 5 years ago

Version: 2.3.2 Support preference Version: AndroidX 1.1.0-alpha04

I get the following crash ocassionally reported by users and the play store console:

android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class net.xpece.android.support.widget.AspSwitchCompat
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class net.xpece.android.support.widget.AspSwitchCompat
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at b.x.I.b(XpPreferenceGroupAdapter.java:53)
at androidx.recyclerview.widget.RecyclerView$a.a(RecyclerView.java:3)
at androidx.recyclerview.widget.RecyclerView$p.a(RecyclerView.java:131)
at androidx.recyclerview.widget.RecyclerView$p.b(RecyclerView.java:1)
at androidx.recyclerview.widget.LinearLayoutManager$c.a(LinearLayoutManager.java:9)
at androidx.recyclerview.widget.LinearLayoutManager.a(LinearLayoutManager.java:107)
at androidx.recyclerview.widget.LinearLayoutManager.a(LinearLayoutManager.java:94)
at androidx.recyclerview.widget.LinearLayoutManager.e(LinearLayoutManager.java:131)
at androidx.recyclerview.widget.RecyclerView.e(RecyclerView.java:37)
at androidx.recyclerview.widget.RecyclerView.c(RecyclerView.java:24)
at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:3)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at d.h.a.d.b.g.b(HeaderScrollingViewBehavior.java:23)
at d.h.a.d.b.h.a(ViewOffsetBehavior.java:1)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:7)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:10)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2496)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2212)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.content.res.Resources$NotFoundException: Drawable my.package:drawable/abc_switch_thumb_material with resource ID #0x7f08004b
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_switch_thumb_material.xml from drawable resource ID #0x7f08004b
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:820)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:630)
at android.content.res.Resources.getDrawableForDensity(Resources.java:877)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.content.Context.getDrawable(Context.java:605)
at b.i.b.a.c(ContextCompat.java:2)
at b.b.f.q.a(AppCompatDrawableManager.java:126)
at b.b.f.q.c(AppCompatDrawableManager.java:1)
at b.b.b.a.a.c(AppCompatResources.java:1)
at b.b.f.ta.b(TintTypedArray.java:3)
at androidx.appcompat.widget.SwitchCompat.<init>(SwitchCompat.java:18)
at net.xpece.android.support.widget.AspSwitchCompat.<init>(AspSwitchCompat.java:1)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at b.x.I.b(XpPreferenceGroupAdapter.java:53)
at androidx.recyclerview.widget.RecyclerView$a.a(RecyclerView.java:3)
at androidx.recyclerview.widget.RecyclerView$p.a(RecyclerView.java:131)
at androidx.recyclerview.widget.RecyclerView$p.b(RecyclerView.java:1)
at androidx.recyclerview.widget.LinearLayoutManager$c.a(LinearLayoutManager.java:9)
at 

This may be caused by an Android bug, backups or users sharing split APKs from what I read on stackoverflow, but thought I let you know, since it might be related to the library. It always happens in the settings screen and nowhere else in my app.

Thanks for looking into it!

consp1racy commented 5 years ago

Hi, thanks for reporting.

Here is the relevant class from this library:

https://github.com/consp1racy/android-support-preference/blob/2.x/support-preference/src/main/java/net/xpece/android/support/widget/AspSwitchCompat.java which extends android.support.v7.widget.SwitchCompat -> androidx.appcompat.widget.SwitchCompat

The class doesn't work with resources at all, everything is handled by the underlying AndroidX implmentation.

Here are some SO questions that may be related: https://stackoverflow.com/questions/50471888/android-app-bundle-introduces-resource-not-found-crash-in-android-app https://stackoverflow.com/questions/51228226/resource-not-found-error-res-drawable-abc-switch-thumb-material-xml-after-adding?noredirect=1&lq=1

I will remove AspSwitchCompat in the next version because it's no longer needed but the error will remain. I don't think I can fix it in this library.

rubengees commented 5 years ago

Thought so, thanks!

There is no branch currently in which the dependency on AspSwitchCompat is already removed correct?

consp1racy commented 5 years ago

It's a waste of time, but I think it's gone in 3.x already. In any case you can copy the switch preference layout to your project and it will override the file provided by this library. In xml replace AspSwitchCompat with SwitchCompat.

What versions of Android did this happen on?

rubengees commented 5 years ago

Ah okay great, I'll try with 3.x then.

This happens on all versions I think, but I'm seeing mostly 9 and 8 since that is what of my users have.