2013-07-02 23 views
0

我遇到了一些麻煩,讓proguard基於它們的註釋(Android下)來保存東西。在proguard中沒有任何效果的註釋

我有一個註釋,com.example.Keep:

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

我有一個類,它永遠只能通過反射構造:

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

    //... 
} 

它將按預期工作(類保持其構造函數儘管帶有混淆的類名)當我的proguard配置包括以下內容:

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

我看到我的兩個自己的註解和proguard相關的annotation.jar標註相同的行爲:,如果我嘗試改變,要它下降的構造。我已經從Foo的Keep導入複製並粘貼了註釋名稱,所以我確信它不是輸入錯誤或導入不正確。

任何人都可以想到我可能會錯過什麼嗎?

回答

4

如果您的註釋被處理的程序代碼,你應該明確地保留他們:

-keep,allowobfuscation @interface * 

的原因是有些技術:ProGuard的可以刪除它們在收縮步驟,因此它們不再有效了優化步驟和混淆步驟。

Cfr。 ProGuard手冊>故障排除>Classes or class members not being kept

相關問題