How to keep class which implement an interface wit

2019-07-14 21:07发布

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.

标签: java proguard
2条回答
一夜七次
2楼-- · 2019-07-14 21:21

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.

查看更多
forever°为你锁心
3楼-- · 2019-07-14 21:45

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>;}
查看更多
登录 后发表回答