使用ProGuard混淆时露出内部类 [英] Exposing inner classes when obfuscating with ProGuard
问题描述
我使用Ant任务混淆库使用ProGuard。
I'm obfuscating a library with ProGuard using the Ant task.
我保持特定的类名和它们的方法名称时,他们有一个特别的注释(@ApiAll),我请求该InnerClasses属性保持:
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>
如果我检查的映射输出文件,我可以看到有注解我的内部类,它的成员都保持自己的名字是非模糊的。然而,当我看到在生成jar文件我找不到类。
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?
推荐答案
您需要指定要使用正确的符号,以保持内部类。
在ProGuard的说法,这意味着 -keep类my.outer.Class $ MyInnerClass
。这里的关键是使用美元符号( $
)的内部和外部类之间的分隔符。
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.
要做到这一点,你还必须指定 -keepattributes InnerClasses
,以便名称 MyInnerClass
不得到模糊处理。这两个设置在一起应该让你的内部类可保持不变。
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.
这篇关于使用ProGuard混淆时露出内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!