如果我有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配置中声明接口名称。
答案 0 :(得分:6)
所以你的.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*
答案 1 :(得分:0)
我写了一篇关于Progaurding Android应用程序的博客。请查看以下链接
http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/
ProGuard可以按照您的描述进行操作。如果您不希望它重命名类和方法,请尝试以下方法:
-keep,allowshrinking,allowoptimization class * { <methods>; }
希望这有帮助