CardView shadow does not appear in Lollipop after obfuscation with proguard

My CardView shadows faded on Lollipop devices after applying Proguard. I did not define any rules for protecting this library because I did not read it at all.

I am putting you a couple of screenshots, first without starting proguard and secon after starting.

Screenshot without proguard

Screenshot with proguard

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 xml as content and does nothing. As you can see, I use two features of cardUseCompatPadding , but this does not solve the problem as it is defined in this thread .

Does anyone know why proguard breaks my shadows?

+5
source share
2 answers

After some diving in library packages, I wrote a rule that protects everything in android.support. ** and now I finally protect only the android.support.v7.widget.RoundRectRrawDrawable file.

So, if you are having problems with this, simply add the following rule to the proguard configuration:

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

FYI, there are some good online collections of Proguard rules needed for each library, for example. https://github.com/krschultz/android-proguard-snippets/

It looks like your Proguard rule has already been absorbed by this project, and it is related to this Stackoverflow question. :-)
https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-support-v7-cardview.pro

0
source

All Articles