Android Proguard - how to keep onClick handlers only referenced from XML layouts

混江龙づ霸主 提交于 2019-12-01 03:14:01

This seems to be the best answer, as it is 100% robust to naming of such methods:

# This will avoid all the onClick listeners referenced from XML Layouts from being removed
-keepclassmembers class * extends android.app.Activity { 
       public void *(android.view.View); 
}

Hope it helps.

-keepclasseswithmembers class * {
   public void onSearchClicked(android.view.View );
}

but double check it from proguard doc : http://proguard.sourceforge.net/index.html#/manual/refcard.html

I use:

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

and then I name all onClick methods like: onCancelBtnClick(), onBackgroundClick(), etc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!