Exposing inner classes when obfuscating with ProGuard

折月煮酒 提交于 2019-12-30 04:38:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!