【问题标题】:CardView shadow not appearing in Lollipop after obfuscate with proguard使用 proguard 混淆后,CardView 阴影未出现在 Lollipop 中
【发布时间】:2015-04-16 15:20:48
【问题描述】:

应用 Proguard 后,我的 CardView 的阴影在 Lollipop 设备上消失了。我没有定义任何规则来保护这个库,因为我没有读过它是必要的。

我附上几张截图,第一次没有运行proguard,第二次运行后。

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 proguard android-cardview


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    仅供参考,每个库都需要一些很好的 Proguard 规则在线集合,例如https://github.com/krschultz/android-proguard-snippets/

    看起来您的 Proguard 规则已被吸收到该项目中,并且它链接回这个 Stackoverflow 问题。 :-)
    https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-support-v7-cardview.pro

    【讨论】:

    • 是的,我通过this PR添加了那里:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 2021-08-10
    相关资源
    最近更新 更多