问题
I'm using my own annotation:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Loggable { }
and obfuscate using Proguard. I use the -keepattributes *Annotation*
in the Proguard configuration to keep the annotations.
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.
However, when I want to apply the same to an annotated method of some class, I retrieve null from someMethod.getAnnotation(Loggable.class).
Is Proguard removing the annotations from methods? How do I tell it not to do so?
I'm using Proguard 4.7.
回答1:
You need to use keepclassmembers parameter:
-keepclassmembers class ** {
@com.yourpackage.Loggable public *;
}
来源:https://stackoverflow.com/questions/30260636/tell-proguard-to-keep-annotation-on-methods