2014-10-03 101 views
0

運行ProGuard後,我遇到了自定義註釋問題。接口註釋和ProGuard

下面是相關的代碼:

註釋

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.TYPE) 
public @interface MyAnnotation { 

} 

類A延伸乙

... 
@MyAnnotation 
public interface CustomInterface { 
} 
... 

抽象類乙

// mClass never found since MyAnnotation seems to be disappeared 
// after obfuscation 
for (Class<?> c : getClass().getClasses()) { 
    for (Annotation annotation : c.getAnnotations()) { 
     if (annotation instanceof MyAnnotation) { 
      mClass = c; 

      break; 
     } 
    } 
} 

我已經嘗試了很多在相關文章中發現的保留語句,但沒有一個適合這種情況。

沒有ProGuard的運行代碼正確地找到mClass成員的類。

的ProGuard配置有:

-keepattributes *Annotation* 

感謝。

回答

0

下面的代碼總是對我的作品

-keepattributes 註釋

+0

謝謝,但我已經有一個定義。 – Niko 2014-10-03 10:35:01

0

下面的聲明似乎來解決這個問題:

-keep @com.mycompany.myapp.MyAnnotation interface * { 
*; 
}