带 SnackBar 和 CoordinatorLayout 的 FloatingActionButton 不适用于混淆器

FloatingActionButton with SnackBar and CoordinatorLayout won't work with proguard

这段简单的代码在启用混淆器的情况下无法正常工作:

<?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>

期望的行为是 FloatingActionButton 在显示时推到 SnackBar 上方,但在我禁用混淆器之前它不会发生。

没有教程也涵盖这一点,因为新项目默认禁用了 proguard ;)

有人知道设计支持库的 proguard 配置吗?

试试这个:

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

Google 已通过 AAR 中的嵌入式 ProGuard 配置修复了此错误。 只需在 build.gradle.

中将设计库依赖项更新为 23+