问题描述
我正在使用我自己的注释:
I'm using my own annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Loggable { }
并使用 Proguard 进行混淆.我使用 -keepattributes *Annotation*
在 Proguard 配置中保留注释.
and obfuscate using Proguard. I use the -keepattributes *Annotation*
in the Proguard configuration to keep the annotations.
在运行时,当我使用 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.
但是,当我想将相同的内容应用于某个类的带注释的方法时,我从 someMethod.getAnnotation(Loggable.class)
中检索 null.
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 在方法上保留注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!