Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing inner classes when obfuscating with ProGuard

Tags:

java

proguard

ant

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?

like image 844
Tom Martin Avatar asked Jul 22 '09 14:07

Tom Martin


2 Answers

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.

like image 129
Markus Jevring Avatar answered Nov 13 '22 13:11

Markus Jevring


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

like image 33
Eric Lafortune Avatar answered Nov 13 '22 13:11

Eric Lafortune