本文介绍了使用 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 class 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 进行混淆时暴露内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 05:36
查看更多