如果我有一个实现Interface A
的Class B
,而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配置中声明接口名称。
- 保留所有公共类名并保留(防止混淆)他们的公共和受保护的方法
- 在非公共类中,保留(防止混淆)所有公共和受保护的方法。这将防止可能实现或扩展其他方法的方法被混淆
- 不保留局部变量属性(使确保"LocalVariableTable"one_answers"LocalVariable TypeTable"不是在"-keepattributes"选项中说明)
所以你的.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*
我写了一个博客,用于Android应用程序的Progaurding。请检查下面的链接
http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/
ProGuard可以做到你所描述的。如果你不想让它重命名类和方法,请尝试以下方法:
-keep,allowshrinking,allowoptimization class * { <methods>; }
希望这能帮助