Mar*_*tin 1 java android proguard
我很难找到基于他们注释的东西(在Android下).
我有一个注释,com.example.Keep:
@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
public @interface Keep {
}
Run Code Online (Sandbox Code Playgroud)
我有一个类,它只是通过反射构建的:
public class Bar extends Foo {
@com.example.Keep
Bar(String a, String b) { super(a, b); }
//...
}
Run Code Online (Sandbox Code Playgroud)
它按预期工作(类保持其构造函数,虽然有一个模糊的类名)当我的proguard配置包括以下内容:
-keepattributes Signature,*Annotation*,SourceFile,LineNumberTable
-keepclassmembers class ** extends com.example.Bar {
<init>(...);
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试将其更改为:它会删除构造函数:
-keepattributes Signature,*Annotation*,SourceFile,LineNumberTable
-keepclassmembers class ** extends com.example.Bar {
@com.example.Keep <init>(...);
}
Run Code Online (Sandbox Code Playgroud)
我用自己的注释和proguard的annotation.jar注释看到了相同的行为.我已经复制并粘贴了Foo导入的注释名称Keep,所以我相信它不是拼写错误或导入错误.
谁能想到我可能会失踪的东西?
如果您的注释正在作为程序代码处理,则应明确保留它们:
-keep,allowobfuscation @interface *
Run Code Online (Sandbox Code Playgroud)
原因有点技术性:ProGuard可能会在缩小步骤中删除它们,因此它们在优化步骤和混淆步骤中不再有效.
(CFR).ProGuard手册>故障排除> 未保留类或类成员.
| 归档时间: |
|
| 查看次数: |
859 次 |
| 最近记录: |