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

前端 未结 3 1624
温柔的废话
温柔的废话 2021-01-11 10:47

In my Android app I ofter don\'t create a View\'s on-click handler in code, but rely on the ability to specify it in the XML layout file, like this:

   

        
相关标签:
3条回答
  • 2021-01-11 11:29
    -keepclasseswithmembers class * {
       public void onSearchClicked(android.view.View );
    }
    

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

    0 讨论(0)
  • 2021-01-11 11:38

    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.

    0 讨论(0)
  • 2021-01-11 11:44

    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.

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