Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obfuscate Parcelable classes with proguard

I'm trying to obfuscate a parcelable class with Proguard:

Before adding the Parcelable part the class is:

public class Foo{

    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}

The obfuscated result is:

public class a
{
  private String a;

  public String a()
  {
    return this.a;
  }

  public void a(String paramString)
  {
    this.a = paramString;
  }
}

After adding implementing parcelable the example class is

public class Foo implements Parcelable {

    private String value;

    private Foo(Parcel in) {
        value = in.readString();
    }

    public Foo() {
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(value);
    }

    public static final Parcelable.Creator<Foo> CREATOR 
        = new Parcelable.Creator<Foo>() {
        public Foo createFromParcel(Parcel in) {
            return new Foo(in);
        }

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

The obfuscated result is

public class Foo implements Parcelable {
    public static final Parcelable.Creator CREATOR = new a();
    private String a;

    public Foo() {
    }

    private Foo(Parcel paramParcel) {
        this.a = paramParcel.readString();
    }

    public String a() {
        return this.a;
    }

    public void a(String paramString) {
        this.a = paramString;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel paramParcel, int paramInt) {
        paramParcel.writeString(this.a);
    }
}

class a implements Parcelable.Creator {
    public Foo a(Parcel paramParcel) {
        return new Foo(paramParcel, null);
    }

    public Foo[] a(int paramInt) {
        return new Foo[paramInt];
    }
}

How can I configure proguard for obfuscate the whole class (including name, params and methods) except the parcelable part?

Thanks

like image 802
Addev Avatar asked Jan 04 '14 01:01

Addev


1 Answers

Try putting this in your proguard.cfg file:

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

That should preserve Parcelable part and obfuscate everything else.

like image 105
Durandal Avatar answered Sep 24 '22 02:09

Durandal