Android Snackbar crashes(android.view.InflateException) with enabled Proguard

Issue

In the Firebase, I start receiving these stack traces:

Fatal Exception: android.view.InflateException
Binary XML file line #1 in {my_project_package_name}:layout/mtrl_layout_snackbar_include: Binary XML file line #1 in {my_project_package_name}:layout/mtrl_layout_snackbar_include: Error inflating class x

The application sometimes also crashes with enabled Proguard when Snackbar is shown.

Solution

I checked the source code of the mtrl_layout_snackbar_include.xml file and found that it depends on the custom google material component:

class="com.google.android.material.snackbar.SnackbarContentLayout"

Since we have a Proguard, this class name will be changed in the compile time.

I fixed this issue by adding these rules to the Proguard to exclude this class name.

# Snackbar
-dontwarn com.google.android.material.**
-keep class com.google.android.material.** { *; }
-keep interface com.google.android.material.** { *; }
-keep public class com.google.android.material.R$* { *; }

Answered By – Veniamin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published