告诉 Proguard 在方法上保留注释 [英] Tell Proguard to keep annotation on methods

查看:37
本文介绍了告诉 Proguard 在方法上保留注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我自己的注释:

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 在方法上保留注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆