Home » Android » android – FloatingActionButton with SnackBar and CoordinatorLayout won't work with proguard

android – FloatingActionButton with SnackBar and CoordinatorLayout won't work with proguard

Posted by: admin June 15, 2020 Leave a comment

Questions:

This simple piece of code won’t work as intended with proguard enabled:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/show"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginTop="40dp"
        android:text="Show snackbar" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_margin="16dp"
        android:src="@drawable/ic_save_white_24dp"
        app:layout_anchorGravity="bottom|right|end" />


</android.support.design.widget.CoordinatorLayout>

Desired behavior is having FloatingActionButton pushed over SnackBar when it is shown, but it doesn’t happen until I disable proguard.

No tutorial also covers this as the new projects has proguard disabled by default 😉

Does anybody know the proguard configuration for Design Support Library?

How to&Answers:

Try this:

# support design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

Answer:

Google has fixed this bug with embedded ProGuard configuration in the AAR.
Just update the design library dependency to 23+ in build.gradle.