How to use Java annotations to guide Android's Proguard?

前端 未结 2 1741
慢半拍i
慢半拍i 2021-02-02 01:39

When using Proguard with Android, methods that are only invoked via reflection (e.g., callbacks defined in onClick XML attributes) are erroneously stripped out.

One solu

相关标签:
2条回答
  • 2021-02-02 02:08

    You can retrieve annotations.jar and annotations.pro from an official ProGuard release. You should then be able to use annotations as discussed here

    All the necessary options can go in proguard.cfg.

    0 讨论(0)
  • 2021-02-02 02:16

    I ran in to this problem recently. Here is what you need to do:

    To fix the onClick events add this to Proguard settings

    -keepclassmembers class * extends android.app.Activity{
       public void *(android.view.View);
    }
    

    To keep annotation add

    -keepattributes ** or -keepattributes *Annotation*

    More information is available here http://www.simpligility.com/2010/12/hints-for-using-proguard-on-your-android-app/ I use maven-android-plugin to compile android app and this article pretty much sums up what I do for the android to get it working. Hope this helps!

    0 讨论(0)
提交回复
热议问题