Tell Proguard to keep annotation on methods

一笑奈何 提交于 2019-12-20 13:58:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!