[英]How to keep class method names that override\implements another method from being obfuscated?
If I have a Class B
that implements Interface A
and Proguard isn't aware of the existence of that interface, How can I keep the names of the methods that implements interface A's abstract methods? 如果我有一个Class B
实现Interface A
而Proguard不知道该接口是否存在,我怎样才能保留实现接口A抽象方法的方法的名称?
Please notice that I want to keep the method names, but I do want their content to be obfuscated. 请注意我想保留方法名称,但我确实希望它们的内容被混淆。
Update: This is what I have (Please notice the comments): 更新:这就是我所拥有的(请注意评论):
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
}
}
I want a general solution for these kind of cases - I don't want to state interfaces names in the ProGuard configuration. 我想要这种情况的一般解决方案 - 我不想在ProGuard配置中声明接口名称。
So your .pro file should look like this - 所以你的.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*
I have writtern a blog for Progaurding the Android application. 我为Progaurding Android应用程序编写了博客。 Please check the link below 请检查以下链接
http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/ http://techspreadwithshraddha.wordpress.com/2013/03/26/android-progaurd/
ProGuard can do what you describe. ProGuard可以按照您的描述进行操作。 If you don't want it to rename classes and methods, Please try the following one : 如果您不希望它重命名类和方法,请尝试以下方法:
-keep,allowshrinking,allowoptimization class * { <methods>; }
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.