Material-components-android: [Snackbar] InflateException thrown on obfuscated builds

Created on 21 Oct 2020  路  13Comments  路  Source: material-components/material-components-android

Description: With ProGuard enabled (minifyEnabled and shrinkResources both true), the Snackbar component crashes with the following exception:

android.view.InflateException: Binary XML file line #1 in my.package.name:layout/mtrl_layout_snackbar_include: Binary XML file line #1 in my.package.name:layout/mtrl_layout_snackbar_include: Error inflating class x
    Caused by: android.view.InflateException: Binary XML file line #1 in my.package.name:layout/mtrl_layout_snackbar_include: Error inflating class x
    Caused by: java.lang.ClassNotFoundException: android.view.x
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at android.view.LayoutInflater.createView(LayoutInflater.java:815)
        at android.view.LayoutInflater.createView(LayoutInflater.java:776)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:913)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:930)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:950)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:659)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)

Expected behavior: Showing a Snackbar should not crash.

Source code:
Snackbar.make(view, "text", Snackbar.LENGTH_SHORT).show()

Android API version: 28, 29

Material Library version: The issue is present both in "1.3.0-alpha03" and "1.2.1".

Device: Samsung Galaxy Note 10+, Google Pixel 3, OnePlus 5

bug

All 13 comments

Hey @pandulapeter ,

I can work on reproducing this on my end and see what's happening.

Have you explored any proguard keep rules with any success?

Hi @hunterstich ,

I've experimented with keeping the com.google.android.material.snackbar.SnackbarContentLayout class as well as anything from com.google.android.material.snackbar.*, without luck. This issue is present on two different projects from our team, I didn't create a separate app just for testing it but it should be easy to reproduce. If it matters, the appCompatVersion is 1.2.0.

Thanks and let me know if I can help with anything!

Ran into this same issue. We worked around it for now by reverting to Gradle 6.1.1 and the 4.0.1 Android Gradle Plugin.

Any update for this?

Can confirm what @orionthewake suggested, it seems to be related to the Gradle build tools version. I also reverted to 4.0.1, but colleagues of mine who don't have this problem are using the newer alpha versions. So maybe the issue only appears on 4.1.0.

I've tried both with plugin version 4.1.1 and 4.2.0-alpha16, same crash with both 馃槥

Still not fixed?

I am using the latest Android Studio 4.2 Beta 1 with plugin version 4.2.0-beta01 and it seems I do not have this crash anymore.

Still crashing for me with plugin 4.2.0-beta01. Maybe some other configuration issue is interfering on my side, I'll give it a try on a brand new project.

For me it is crashing in release if I have minify enabled, even if the proguard file has the -dontobfuscate rule.

But if I try to debug it (isDebuggable = true) the app stop crashing.

Using plugin 4.1.1 Temporarily fixed downgrading to 4.0.1

It seems that I turned on isDebuggable on my release test build. Yeah still not fixed

Adding this to your proguard-rules.pro should fix the issue: -keep class com.google.android.material.snackbar.** { *; }

Maybe can be broken down to be more precise.

Tested with Gradle Plugin 7.0.0-alpha03

Was this page helpful?
0 / 5 - 0 ratings