问题
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?
回答1:
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.
回答2:
The option keepclassmembers
only preserves the specified class members (and their names).
You probably want the more common option keep
, which preserves the specified classes and class members (and their names).
Cfr. ProGuard manual > Usage > Overview of Keep Options
来源:https://stackoverflow.com/questions/1165658/exposing-inner-classes-when-obfuscating-with-proguard