Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CardView shadow not appearing in Lollipop after obfuscate with proguard

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.

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

like image 319
Ignasi Avatar asked Apr 16 '15 15:04

Ignasi


People also ask

How to use cardview in Android Studio?

CardView can be used for creating items in listview or inside Recycler View. The best part about CardView is that it extends Framelayout and it can be displayed on all platforms of Android. Now we will see the simple example of CardView implementation. Step 1: Create a new Android Studio Project. For creating a new Android Studio Project.

How do I add cardview dependencies to my project?

To add a dependency on CardView, you must add the Google Maven repository to your project. Read Google's Maven repository for more information. Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

What are the Android ProGuard rules?

The Android ProGuard rules include some safe defaults for every Android app, such as making sure View getters and setters - which are normally accessed through reflection - and many other common methods and classes are not stripped out.

How do I See removed nodes in a ProGuard tree?

You can enable the “Show removed nodes” option to see anything that was removed by ProGuard (shown in strikethrough). Right clicking on a node in the tree lets you generate a keep rule that you can paste in your ProGuard configuration file.


1 Answers

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 { *; }
like image 112
Ignasi Avatar answered Sep 20 '22 19:09

Ignasi