Tell Proguard to keep annotation on methods

2019-03-20 12:09发布

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条回答
Melony?
2楼-- · 2019-03-20 13:08

You need to use keepclassmembers parameter:

-keepclassmembers class ** {
  @com.yourpackage.Loggable public *;
}
查看更多
登录 后发表回答