Tell Proguard to save annotation on methods

I use my own annotation:

@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface Loggable { } 

and get confused with Proguard. I use -keepattributes *Annotation* in the Proguard configuration to save annotations.

At runtime, when I retrieve the annotation from the annotated class using someClass.getAnnotation(Loggable.class) , everything works - I retrieve a non-zero instance of my annotation.

However, when I want to apply the same to the annotated method of some class, I get null from someMethod.getAnnotation(Loggable.class) .

Is Proguard removing annotations from methods? How can I tell you not to do this?

I am using Proguard 4.7.

+7
java android annotations proguard
source share
1 answer

You need to use the keepclassmembers parameter:

 -keepclassmembers class ** { @com.yourpackage.Loggable public *; } 
+10
source share

All Articles