Exposing inner classes when obfuscating with ProGuard

ant, java, proguard

Solution

You need to specify that you want to keep the inner class using the proper notation. In the proguard parlance, that means `-keep class my.outer.Class$MyInnerClass`. The key here is using the dollar-sign (`$`) as the separator between inner and outer class.

To do this, you also have to specify `-keepattributes InnerClasses`, so that the name `MyInnerClass` doesn't get obfuscated. These two settings together should allow your inner classes to be kept intact.

Problem

I'm obfuscating a library with ProGuard using the Ant task. I'm keeping particular class names and their method names when they have a particular annotation (@ApiAll) and I'm requesting that the InnerClasses attribute be kept: ``` <keepattribute name="InnerClasses" /> <keep annotation="com.example.ApiAll"/> <keepclassmembers annotation="com.example.ApiAll"> <constructor access="public protected"/> <field access="public protected"/> <method access="public protected"/> <constructor access="protected"/> </keepclassmembers> ``` If I check the mapping output file I can see that my inner class that has the annotation and it's members are keeping their names unobfuscated. However when I look in the generated jar file I can't find the class. Am I missing something? Why is the mapping telling me it's keeping this class when it's not?

Original source