Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaterialRatingDrawable Crash #76

Open
keepmovingljzy opened this issue Feb 1, 2021 · 15 comments
Open

MaterialRatingDrawable Crash #76

keepmovingljzy opened this issue Feb 1, 2021 · 15 comments

Comments

@keepmovingljzy
Copy link

Hi,there will crash on the Nexus 5x and Huawei Enjoy 9s
My MaterialRatingBar version is 1.4.0 is the latest
This is crash log

Fatal Exception: android.view.InflateException
Binary XML file line #9: Binary XML file line #51: Error inflating class com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar
android.view.LayoutInflater.createView (LayoutInflater.java:633)
android.view.LayoutInflater.inflate (LayoutInflater.java:414)
com.xxx.xxx.module_base.ui.widget.adapter.BaseRecyclerViewAdapter.onCreateViewHolder (BaseRecyclerViewAdapter.java:26)
com.yanzhenjie.recyclerview.AdapterWrapper.onCreateViewHolder (AdapterWrapper.java:123)
androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:7046)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:698)

Caused by android.view.InflateException
Binary XML file line #51: Error inflating class com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar
java.lang.reflect.Constructor.newInstance (Constructor.java)
android.view.LayoutInflater.inflate (LayoutInflater.java:414)
com.xxx.xxx.module_base.ui.widget.adapter.BaseRecyclerViewAdapter.onCreateViewHolder (BaseRecyclerViewAdapter.java:26)
com.yanzhenjie.recyclerview.AdapterWrapper.onCreateViewHolder (AdapterWrapper.java:123)
androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:7046)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:698)
Caused by android.content.res.Resources$NotFoundException
Resource ID #0x7f08019b
android.content.res.Resources.getValue (Resources.java:1266)
androidx.appcompat.content.res.AppCompatResources.getDrawable (AppCompatResources.java:104)
me.zhanghai.android.materialratingbar.MaterialRatingDrawable.createLayerDrawableWithTintColor (MaterialRatingDrawable.java:43)
me.zhanghai.android.materialratingbar.MaterialRatingDrawable.createLayerDrawableWithTintAttrRes (MaterialRatingDrawable.java:54)
me.zhanghai.android.materialratingbar.MaterialRatingDrawable. (MaterialRatingDrawable.java:23)
me.zhanghai.android.materialratingbar.MaterialRatingBar.init (MaterialRatingBar.java:105)
me.zhanghai.android.materialratingbar.MaterialRatingBar. (MaterialRatingBar.java:52)
com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar. (CustomRatingBar.java:14)
com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar. (CustomRatingBar.java:13)
com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar. (CustomRatingBar.java:13)
java.lang.reflect.Constructor.newInstance (Constructor.java)
android.view.LayoutInflater.inflate (LayoutInflater.java:414)
com.xxx.xxx.module_base.ui.widget.adapter.BaseRecyclerViewAdapter.onCreateViewHolder (BaseRecyclerViewAdapter.java:26)
com.yanzhenjie.recyclerview.AdapterWrapper.onCreateViewHolder (AdapterWrapper.java:123)
androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:7046)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:698)

This is CustomRatingBar code:

class CustomRatingBar @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : MaterialRatingBar(context, attrs, defStyleAttr)

@zhanghai

@keepmovingljzy
Copy link
Author

my ui

<com.xxx.xxx.module_base.ui.widget.ratingbar.CustomRatingBar
            android:id="@+id/ratingbar"
            style="@style/ProductRatingBarForDetailPLP"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="2dp" />

<style name="ProductRatingBarForDetailPLP">
        <item name="mrb_progressTint">@color/ratingBarColor</item>
        <item name="mrb_progressBackgroundTint">@color/ratingBarGrayBgColor</item>
        <item name="android:stepSize">0.5</item>
        <item name="android:minHeight">12dp</item>
        <item name="android:maxHeight">12dp</item>
        <item name="android:numStars">5</item>
        <item name="android:isIndicator">true</item>
    </style>            

@keepmovingljzy
Copy link
Author

@zhanghai

@zhanghai
Copy link
Owner

Could you try the sample app on those devices? If it works fine, it's probably your code/configuration causeing the crash.

@keepmovingljzy
Copy link
Author

It will 100% crash on Huawei Enjoy 9,But on Nexus 5x May be 2%,and some Motorola devices
image
I have the Huawei Enjoy 9,so the sample app will crash,but Nexus 5x is hard to reproduct the crash.

@keepmovingljzy
Copy link
Author

@zhanghai

@zhanghai
Copy link
Owner

Can you share the crash stacktrace for the sample app? Definitely an OEM issue if it's only broken on OEM devices, but we may work around if we know the root cause.

I don't have a Huawei device so I can't test this. My Pixel 4 XL running Android 11 runs the sample app fine.

@keepmovingljzy
Copy link
Author

Sorry,the Huawei Enjoy 9 not by my side,I test the sample app through my friends,I can't get the crash stacktrace.
I show my code in front of this issue,I just extends MaterialRatingBar class,not do anything else.This code has run in so many devices(more than 10000),so the code doesn't have the problem.
All of the crashes was on Android 5 Devices,So may be the Android 5 Devices will reproduce this crash.
I also show the crashes stacktrace in front of this issue. you can see it again.

@keepmovingljzy
Copy link
Author

@zhanghai

@keepmovingljzy
Copy link
Author

The Nexus 5X is android 8,sometimes it also crash
image

@keepmovingljzy
Copy link
Author

This crash shows when I use the app bundle‘s version,before this I used the apk,it was never show this crash.

@keepmovingljzy
Copy link
Author

@zhanghai

@zhanghai
Copy link
Owner

Then it's probably app bundle resources not properly bundled, or app bundle resource handling broken on those devices, if APK works well. Which matches good with the exception stacktrace saying resource not fond. I haven't ventured into app bundle so I don't know much about it for now.

@pballart
Copy link

pballart commented Aug 12, 2021

Hello! I'm having a very similar issue. In my case it only happens to API Level 21 and 22 (weird) but it seems pretty related to the new app bundles. Here it is my stack trace:

Caused by java.lang.VerifyError: Verifier rejected class uf.b due to bad method void uf.b.setTintList(android.content.res.ColorStateList) (declaration of 'uf.b' appears in /data/app/com.my.app-1/base.apk:classes2.dex)
       at me.zhanghai.android.materialratingbar.MaterialRatingDrawable.createClippedLayerDrawableWithTintAttrRes(MaterialRatingDrawable.java:68)
       at me.zhanghai.android.materialratingbar.MaterialRatingDrawable.<init>(MaterialRatingDrawable.java:29)
       at me.zhanghai.android.materialratingbar.MaterialRatingBar.init(MaterialRatingBar.java:105)
       at me.zhanghai.android.materialratingbar.MaterialRatingBar.<init>(MaterialRatingBar.java:46)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:626)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)

It only happens when you build for release, but seems unrelated to proguard and obfuscation

@furkanyurdakul
Copy link

Hello! I'm having a very similar issue. In my case it only happens to API Level 21 and 22 (weird) but it seems pretty related to the new app bundles. Here it is my stack trace:

Caused by java.lang.VerifyError: Verifier rejected class uf.b due to bad method void uf.b.setTintList(android.content.res.ColorStateList) (declaration of 'uf.b' appears in /data/app/com.my.app-1/base.apk:classes2.dex)
       at me.zhanghai.android.materialratingbar.MaterialRatingDrawable.createClippedLayerDrawableWithTintAttrRes(MaterialRatingDrawable.java:68)
       at me.zhanghai.android.materialratingbar.MaterialRatingDrawable.<init>(MaterialRatingDrawable.java:29)
       at me.zhanghai.android.materialratingbar.MaterialRatingBar.init(MaterialRatingBar.java:105)
       at me.zhanghai.android.materialratingbar.MaterialRatingBar.<init>(MaterialRatingBar.java:46)
       at java.lang.reflect.Constructor.newInstance(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
       at android.view.LayoutInflater.createView(LayoutInflater.java:626)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)

It only happens when you build for release, but seems unrelated to proguard and obfuscation

I've found the reason for this, and a solution, however I'm not entirely sure why it happens. Using a gradle version more than 4.2.2 with R8 optimization enabled (via app level build.gradle proguardFiles ('proguard-android-optimize.txt') 'proguard-rules.pro') causes something to change in one of the core libraries of Android. This change affects API 21 and 22 devices where the super method setTintList(ColorStateList) of the Drawable class not to be found, causing this error. The line that causes this error to happen is at ClipDrawableCompat.java where the setTintList(ColorStateList tint) method is overriden, at the super call. Disabling optimization on Proguard using proguardFiles ('proguard-android.txt') 'proguard-rules.pro' or downgrading the gradle version from 7.0.2 (or above) to 4.2.2 seems to be solving this problem.

Again, not entirely sure why it happens, but this approach seems to be solving it. The downside is that the APK size becomes a bit bigger.

@lUjek-Sh
Copy link

I solved the problem for myself by abandoning the Gradle Kotlin DSL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants