1

I want to obfuscate my app with ProGuard and I also want member of some inner classes to keep their names. This is because I use these classes in Jackson for converting to and from JSON. My source:

// this class mainly serves as a container for a group of related inner classes
public class MyOuterClass
{
    public class IDontWantToKeepThisClassName1
    {
        public String IWantToKeepThisName1;
        public float IWantToKeepThisName2;
    }

    public class IDontWantToKeepThisName2
    {
        public IDontWantToKeepThisClassName1 IWantToKeepThisName3;
        public float    IWantToKeepThisName4;
    }

}

I hope that above code is self explanatory. I tried to achieve this with this command in proguard-project.txt

-keepclassmembernames class com.myapppackage.MyOuterClass$**

Yet this does not work. Inner class members are still obfuscated. It takes insane amount of time to test various options trying to guess correct options or syntax because each change requires package export to see if it works.

f470071
  • 1,527
  • 3
  • 18
  • 30

1 Answers1

2

I am pretty sure something like this should do the trick:

-keepclassmembernames class com.myapppackage.MyOuterClass$** { *; }

So please double check. Testing showed that { *; } part is necessary. Although I cannot explain why. Could someone with insight please elaborate.

  • Thank you. Yes, I checked. { *; } must be included. Although I find this very counerintuitive. Perhaps someone could add an explanation. – f470071 May 13 '15 at 16:21
  • That is a wild card to keep that says that condition is applicable for all the lines, instead you can use some other wild card to specify all fields and all methods. But technically both are same. – Saran Sankaran Apr 11 '18 at 11:06