应用Proguard后,我的CardView阴影在Lollipop设备上消失了。我没有定义任何保护该库的规则,因为我根本没有读过它。

我附上了几个屏幕截图,首先是不运行proguard的屏幕截图,然后是运行后的secon。

Screenshot without proguard

Screenshot with proguard

这是我的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            tools:context=".MainActivity">

    <android.support.v7.widget.CardView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_margin="4dp"
        app:contentPadding="10dp"
        app:cardUseCompatPadding="true">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 1"/>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_margin="4dp"
        app:contentPadding="10dp"
        app:cardUseCompatPadding="false">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text 2"/>
    </android.support.v7.widget.CardView>

</LinearLayout>

Activity 仅将xml设置为内容,并且仅执行其他操作。
如您所见,我正在使用cardUseCompatPadding的两种可能性,但是它不能解决this thread中定义的问题。

有人知道为什么proguard破坏了我的阴影吗?

最佳答案

在库包中进行了一些深入研究之后,我写了一条规则来保护android.support。**上的所有内容,现在我终于只保护了android.support.v7.widget.RoundRectDrawable。

因此,如果您对此有疑问,只需在您的proguard配置中添加下一条规则:

-keep class android.support.v7.widget.RoundRectDrawable { *; }

10-06 13:22
查看更多