How can I tell ProGuard to keep my function that is used for onClick?

前端 未结 3 1027
囚心锁ツ
囚心锁ツ 2021-02-05 16:19

I am using the android:onClick atribute in some of my .xml layout files for my android application, but ProGuard is removing these methods from my code when it runs

相关标签:
3条回答
  • 2021-02-05 16:51

    According to proguard documentation:

    Fields and methods may also be specified using regular expressions. Names can contain the following wildcards: ? matches any single character in a method name. * matches any part of a method name.

    so, you will be find specifying

    -keep class com.example.MyClass {
      public void listener_*(android.view.View);
    }
    

    in your proguard flags.

    0 讨论(0)
  • 2021-02-05 17:10

    You can do it once for all your classes in this way:

    -keepclasseswithmembers class * {
        void listener_*(...);
    }
    
    0 讨论(0)
  • 2021-02-05 17:14

    An a bit more greedy approach that should keep all "onClick" methods:

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

    ==> so basically every public method that has an Android View as the only Paramater should survive ProGuard then.

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