Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 because nothing in my code is ever calling them.

Rather then specifying each function individually, I would like to name them something like listener_functionName, and use wildcards, like -keep listener_* (I know this is incorrect, but hopefully it illustrates my goal).

If this is possible that would be great, but if not I still need to know how to specify these functions in the proguard.cfg file. Any help is appreciated.

like image 952
finiteloop Avatar asked May 21 '11 22:05

finiteloop


2 Answers

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.

like image 83
Diego Torres Milano Avatar answered Sep 25 '22 20:09

Diego Torres Milano


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

-keepclasseswithmembers class * {
    void listener_*(...);
}
like image 34
ggurov Avatar answered Sep 22 '22 20:09

ggurov