martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

Infrequent Crashing with Resources$NotFoundException #62

Open stealthcopter opened 10 months ago

stealthcopter commented 10 months ago

Hey this is a great library and I'm using it in production and I'm noticing very infrequent crashes on some specific devices. It seems it is not able to find the drawable checker_background when inflating color_preference_thumbnail.xml.

Fatal Exception: android.view.InflateException
Binary XML file line #31 in <package_name>:layout/color_preference_thumbnail: Binary XML file line #31 in com.stealthcopter.nexusrevampedpro:layout/color_preference_thumbnail: Error inflating class ImageView
Caused by android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f080081
       at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:304)
       at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:885)
       at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:731)
       at android.content.res.Resources.loadDrawable(Resources.java:1020)
       at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:1017)
       at android.content.res.TypedArray.getDrawable(TypedArray.java:991)
       at android.widget.ImageView.<init>(ImageView.java:211)
       at android.widget.ImageView.<init>(ImageView.java:197)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:73)
       at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:233)
       at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:152)
       at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1678)
       at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1729)
       at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1077)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1013)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:977)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:1139)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1100)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:693)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:542)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
       at com.rarepebble.colorpicker.ColorPreference.addThumbnail(ColorPreference.java:153)
       at com.rarepebble.colorpicker.ColorPreference.onBindViewHolder(ColorPreference.java:88)
       at androidx.preference.PreferenceGroupAdapter.onBindViewHolder(PreferenceGroupAdapter.java:422)
       at androidx.preference.PreferenceGroupAdapter.onBindViewHolder(PreferenceGroupAdapter.java:49)
       at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)
       at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)
       at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
       at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
       at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
       at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3851)
       at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4404)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1841)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:536)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1841)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
       at com.android.internal.policy.DecorView.onLayout(DecorView.java:866)
       at android.view.View.layout(View.java:24006)
       at android.view.ViewGroup.layout(ViewGroup.java:6512)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:4194)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3524)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2458)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9478)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1412)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1420)
       at android.view.Choreographer.doCallbacks(Choreographer.java:1047)
       at android.view.ChoreographerExtImpl.checkScrollOptSceneEnable(ChoreographerExtImpl.java:451)
       at android.view.Choreographer.doFrame(Choreographer.java:918)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1395)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:240)
       at android.os.Looper.loop(Looper.java:351)
       at android.app.ActivityThread.main(ActivityThread.java:8422)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

I'm wondering if this is something to do with using the .aab format and Google Play stripping out what it thinks are the unneeded resources. I've noticed the drawable only exists in mdpi hdpi and xhdpi. Do you have any insight into this? thank you.

martin-stone commented 10 months ago

Hi. I've not experienced this myself, although I'm still using APK format on my projects.

It does seem like an Android bug, as the docs say...

If you don't provide a density-specific resource for that density, the system locates the next-best match and scales it to fit the screen.

I'd happily accept a PR that adds extra densities if you think that would solve it.