如何使用Java注解来指导Android的Proguard?
当在 Android 中使用 Proguard 时,仅通过反射调用的方法(例如,onClick XML 属性中定义的回调)会被错误地删除。
此问题的一个解决方案是将每个受影响的类和方法添加到您的混淆器中.cfg。
如何使用Java注解来达到同样的效果?
我觉得这将使代码自我记录,并且可以避免代码和 proguard.cfg 不同步。然而,Android 的 Proguard 似乎没有附带其文档中提到的annotations.jar。
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 solution for this issue is to add each affected class and method to your proguard.cfg.
How can I use Java annotations to achieve the same effect?
I feel that would make the code self-documenting and it would avoid code and proguard.cfg drifting out of sync. However, Android's Proguard doesn't seem to ship with the annotations.jar mentioned in its documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从官方 ProGuard 版本中检索
annotations.jar
和annotations.pro
。然后,您应该能够使用此处讨论的注释。所有必要的选项都可以进入 proguard.cfg。
You can retrieve
annotations.jar
andannotations.pro
from an official ProGuard release. You should then be able to use annotations as discussed hereAll the necessary options can go in proguard.cfg.
我最近遇到了这个问题。您需要执行以下操作:
要修复 onClick 事件,请将其添加到 Proguard 设置
要保留注释,请添加
-keepattributes **
或-keepattributes *Annotation*
提供更多信息这里http://www.simpligility.com/2010/ 12/hints-for-using-proguard-on-your-android-app/ 我使用 maven-android-plugin 来编译 android 应用程序,这篇文章几乎总结了我为 android 工作所做的工作。希望这有帮助!
I ran in to this problem recently. Here is what you need to do:
To fix the onClick events add this to Proguard settings
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!