问题
I defined an annotation named @KeepAll.
I have an interface like
@KeepAll
public interface MainEntity {
//some methods
}
I want to keep all classes which implement this interface from obfuscation. Is this possible on ProGuard?
NOTE I know I can define it as
-keep public class * implements **.MainEntity
But I don't want to specify interface name but annotation name.
回答1:
After a long trial and error process I get what I want. Here is the solution
Keep class names with annotation KeepAll;
-keep @com.package.name.KeepAll public class **
Keep class members of classes and interface with annotation KeepAll;
-keepclassmembers @com.package.name.KeepAll class ** { public <methods>; <fields>;}
Keep class members of a class which implemets a class that has KeepAll annotation. (This was what I want)
-keepclassmembers public class * implements @com.package.name.KeepAll ** { public <methods>; <fields>;}
回答2:
You can tell ProGuard to keep everything with an annotation like this:
-keep @com.google.inject.Singleton public interface *
The above would keep the interface itself from obfuscation.
To get the implementations of the interface you can do something like this:
-keep public class * implements **.MainEntity
So Right now I am confused what you want to achieve. If you only annotate the interface it wont be a help for ProGuard. The classes would need this annotation.
来源:https://stackoverflow.com/questions/45833694/how-to-keep-class-which-implement-an-interface-with-annotation