注释对proguard没有影响 [英] annotations having no effect in proguard

查看:238
本文介绍了注释对proguard没有影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据他们的注释(在Android下),我很难找到保存内容的程序。

I'm having troubles getting proguard to keep things based on their annotations (under Android).

我有一个注释,com.example.Keep:

I have an annotation, com.example.Keep:

@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
public @interface Keep {
}

我有一个类,它只能通过反射构建:

I have a class, which is only ever constructed through reflection:

public class Bar extends Foo {
    @com.example.Keep
    Bar(String a, String b) { super(a, b); }

    //...
}

它有效正如预期的那样(类保留其构造函数,尽管有一个模糊的类名)当我的proguard配置包含以下内容时:

It works as expected (class keeps its constructor albeit with an obfuscated class name) When my proguard config includes the following:

-keepattributes Signature,*Annotation*,SourceFile,LineNumberTable
-keepclassmembers class ** extends com.example.Bar {
<init>(...);
}

如果我尝试将其更改为:

It drops the constructor if I try change that to:

-keepattributes Signature,*Annotation*,SourceFile,LineNumberTable
-keepclassmembers class ** extends com.example.Bar {
@com.example.Keep <init>(...);
}

我在自己的注释和proguard的annotation.jar注释中看到了相同的行为。我已经复制并粘贴了Foo导入的 Keep 中的注释名称,所以我相信它不是拼写错误或导入错误。

I see the same behaviour with both my own annotations and proguard's annotation.jar annotations. I've copied and pasted the annotation name from Foo's import of Keep, so am confident it's not a typo or incorrect import.

有人能想到我可能缺少的东西吗?

Can anyone think of what I might be missing?

推荐答案

如果您的注释正在作为程序代码处理,应明确保留它们:

If your annotations are being processed as program code, you should explicitly preserve them:

-keep,allowobfuscation @interface *

原因有点技术性:ProGuard可能会在缩小步骤中删除它们,因此它们在优化步骤和混淆步骤中不再有效。

The reason is somewhat technical: ProGuard may remove them in the shrinking step, so they are no longer effective in the optimization step and the obfuscation step.

Cfr。 ProGuard手册>故障排除> 不保留课程或班级成员

Cfr. ProGuard manual > Troubleshooting > Classes or class members not being kept.

这篇关于注释对proguard没有影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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