如何保留通过注释实现接口的类 [英] How to keep class which implement an interface with annotation

查看:152
本文介绍了如何保留通过注释实现接口的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了一个名为@KeepAll的注释.

I defined an annotation named @KeepAll.

我有一个类似的界面

@KeepAll
public interface MainEntity {
    //some methods
}

我想防止实现该接口的所有类混淆.在ProGuard上有可能吗?

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.

推荐答案

经过长时间的反复试验,我得到了想要的东西.这是解决方案

After a long trial and error process I get what I want. Here is the solution

保留带有注释KeepAll的类名称;

Keep class names with annotation KeepAll;

-keep @com.package.name.KeepAll public class **

保留类的类成员并使用注释KeepAll进行接口;

Keep class members of classes and interface with annotation KeepAll;

-keepclassmembers @com.package.name.KeepAll class ** { public <methods>; <fields>;}

保留实现带有KeepAll批注的类的类的类成员. (这就是我想要的)

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>;}

这篇关于如何保留通过注释实现接口的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆