Identify inner classes when obfuscated with ProGuard

I am obfuscating the library using ProGuard using the Ant task.

I save certain class names and their method names when they have a specific annotation (@ApiAll), and I ask you to keep the InnerClasses attribute:

<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 output mapping file, I see that my inner class, which has the annotation, and its members will not take pictures of their names. However, when I look in the generated jar file, I cannot find the class.

Am I missing something? Why does the mapping tell me that it saves this class when it doesn't work?

+6
java ant proguard
source share
2 answers

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

For this, you also need to specify -keepattributes InnerClasses , so the name MyInnerClass will not be confused. These two settings together should allow your inner classes to remain intact.

+20
source share

Only the specified class members (and their names) are saved in the keepclassmembers option.

You probably need a more general version of keep that saves the specified classes and class members (and their names).

CFR. ProGuard Guide> Usage> Overview of Save Options

0
source share

All Articles