如何使用 Android 配置 Proguard,使其不会删除仅在 XML 布局中引用的事件处理程序方法?
我有许多活动,其中当用户点击某些 UI 元素时要执行的处理程序方法被 Proguard 删除,因为它看不到它正在被使用。
对此最好的解决方案是什么?
关闭proguard中的代码收缩功能(不理想,因为它在很多领域都有好处)
有吗有一种方法可以注释我希望它保留的方法吗?
如何调整混淆器配置以永远不删除以“on”开头的方法?
我尝试添加这一行(即不要修剪从 Activity 对象的子类继承的方法),但它没有达到预期的效果。我认为它适用于类,但不适用于它们的方法。
-keep public class * extends com.myapp.CustomActivity
I've a number of activities where the handler method to be executed when the user taps certain UI elements is being stripped by Proguard because it can't see that it's being used.
What's the best solution to this?
Turn off the code shrink feature in proguard (not ideal as it is beneficial in many areas)
Is there a way to annotate methods I want it to leave in?
How can I tweak a proguard config to never remove methods that start with "on"?
I tried adding this line (i.e. don't trim methods inheriting from my sublass of the Activity object) but it didn't have the desired effect. I assume it applies to the classes, but not their methods.
-keep public class * extends com.myapp.CustomActivity
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于要维护的每个方法,请在 proguard 文件中添加另一行:
-keepclassmembers class * {
公共无效 exampleMethodName1(android.view.View);
公共无效 exampleMethodName2(android.view.View);
...
您可以在以下
位置找到此主题:Android 中的 Proguard 和反射
For each method you want to maintain add another line to the proguard file:
-keepclassmembers class * {
public void exampleMethodName1(android.view.View);
public void exampleMethodName2(android.view.View);
...
}
You can find this topic addressed at: Proguard and reflection in Android