My CardView's shadows have disappeared on Lollipop devices after applying Proguard. I haven't defined any rule to protect this library, because I haven't read it was necessary at all.
I attach you a couple of screenshots, first without running proguard, and secon after running it.
And this is my 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 only sets the xml as content and does nothing more.
As you can see, I'm using the two possibilities of cardUseCompatPadding
, but it doesn't solve the issue as it's defined in this thread.
Does anybody know why proguard is breaking my shadows?
After some diving in the library packages, I wrote a rule that protected everything at android.support.** and now I'm finally protecting just android.support.v7.widget.RoundRectDrawable.
So if you are having troubles with this, just add the next rule at your proguard config:
-keep class android.support.v7.widget.RoundRectDrawable { *; }
FYI, there are some good online collections of the Proguard rules required for each library, e.g. https://github.com/krschultz/android-proguard-snippets/
It looks like your Proguard rule has already been absorbed into that project, and it links back to this Stackoverflow question. :-)
https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-support-v7-cardview.pro
来源:https://stackoverflow.com/questions/29679177/cardview-shadow-not-appearing-in-lollipop-after-obfuscate-with-proguard