sha February 2016

Android - Proguard stripping away Parcelable Creator

I have a library project which has Proguard rules on it. These are stated below

  -keep class * implements android.os.Parcelable {
     public static final android.os.Parcelable$Creator *;
  }

  -keepclassmembers class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
  }

One of my classes named Actor implements Parcelable whose creator is like

public static final Creator<Actor> CREATOR = new Creator<Actor>()
{
    public Actor createFromParcel(Parcel pc)
    {
        return new Actor(pc);
    }

    public Actor[] newArray(int size)
    {
        return new Actor[size];
    }
};

Then, AAR is created and I am importing the library project to my project using compile in gradle. Then I am trying to run the project in release mode which is giving me issues saying Warning:com.xtlib.models.Actor: can't find referenced class a

I looked into the code of Actor which looks like

public static final Creator<Actor> CREATOR = new a();

Even though Proguard is not changing "CREATOR" name, it is changing the implementation. How can I skip proguard changing my declaration to a variable

Regards,
Sree

Answers


sha February 2016

I figured out the issue. The issue is with latest gradle plugin 1.5.0. The latest gradle is placing the generated anonymous classes(ex : a.class) outside the package structure.

enter image description here

When I reverted my Gradle plugin to 1.2.3 for generating AAR, the generated classes are moved to their respective packages.

enter image description here

This solved my issue.

Cheers

Post Status

Asked in February 2016
Viewed 3,045 times
Voted 8
Answered 1 times

Search




Leave an answer