问题描述
我正在使用自己的注释:
I'm using my own annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Loggable { }
and obfuscate使用Proguard。我在Proguard配置中使用 -keepattributes * Annotation *
来保留注释。
and obfuscate using Proguard. I use the -keepattributes *Annotation*
in the Proguard configuration to keep the annotations.
At运行时,当我从带注释的类中使用 someClass.getAnnotation(Loggable.class)
检索注释时,一切正常 - 我检索一个非空实例我的注释。
At runtime, when I retrieve the annotation from an annotated class using someClass.getAnnotation(Loggable.class)
everything works - I retrieve a non-null instance of my annotation.
然而,当我想将它应用于某个类的带注释的方法时,我从<$ c中检索null $ c> someMethod.getAnnotation(Loggable.class)。
However, when I want to apply the same to an annotated method of some class, I retrieve null from someMethod.getAnnotation(Loggable.class)
.
Proguard是否从方法中删除了注释?我怎么告诉它不要这样做?
Is Proguard removing the annotations from methods? How do I tell it not to do so?
我正在使用Proguard 4.7。
I'm using Proguard 4.7.
推荐答案
您需要使用 keepclassmembers
参数:
-keepclassmembers class ** {
@com.yourpackage.Loggable public *;
}
这篇关于告诉Proguard保留方法的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!