繁体   English   中英

如何保持覆盖\\实现另一个方法的类方法名称被混淆?

[英]How to keep class method names that override\implements another method from being obfuscated?

如果我有一个Class B实现Interface A而Proguard不知道该接口是否存在,我怎样才能保留实现接口A抽象方法的方法的名称?

请注意我想保留方法名称,但我确实希望它们的内容被混淆。

更新:这就是我所拥有的(请注意评论):

public class MyService extends Service {

   // an anonymous class that implements ServiceConnection 
   private ServiceConnection myConnection = new ServiceConnection()
   {
      // don't change the following method's name
      @Override
      public void onServiceConnected(ComponentName className, IBinder service)
      {
          // I want this section to be obfuscated
      }

}

我想要这种情况的一般解决方案 - 我不想在ProGuard配置中声明接口名称。

  • 保留所有公共类名称并保持(防止混淆)其公共和受保护的方法。
  • 在非公共类中,保持(防止混淆)所有公共和受保护的方法。 这将使可能实现或扩展其他方法的方法不被混淆。
  • 不要保留局部变量属性(确保“-keepattributes”选项中未声明“LocalVariableTable”和“LocalVariableTypeTable”)。

所以你的.pro文件应该是这样的 -

#Keeping all public class names and keep (prevent obfuscation) of their public and protected methods
-keep public class * {
    public protected <methods>;
}

# Keep (prevent obfuscation) all public and protected methods in non-public classes.
# Notice that the non-public class names will still get obfuscated
-keepclassmembers !public class * {
    public protected <methods>;
}

# Don't keep the local variables attributes (LocalVariableTable and LocalVariableTypeTable are dropped).
-keepattributes Exceptions,Signature,Deprecated,SourceFile,SourceDir,LineNumberTable,Synthetic,EnclosingMethod,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,AnnotationDefault,InnerClasses,*Annotation*

我为Progaurding Android应用程序编写了博客。 请检查以下链接

http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/

ProGuard可以按照您的描述进行操作。 如果您不希望它重命名类和方法,请尝试以下方法:

-keep,allowshrinking,allowoptimization class * { <methods>; }

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM