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

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (2 by maintainers)

Commits related to this issue

Most upvoted comments

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

Seems this is an issue on the R8 side: https://issuetracker.google.com/issues/174167294

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

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.

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.