android:onClick not working with ProGuard

前端 未结 2 1750
独厮守ぢ
独厮守ぢ 2021-01-03 03:08

Since today, something weird is happening with my application. Every time I click a button that has set the android:onClick attribute, I get an IllegalStateException: Co

相关标签:
2条回答
  • 2021-01-03 03:58

    You need to tell proguard not to mutate the method associated with your android:onClick tag.

    Here is an example rule (taken from the proguard website):

    -keep class mypackage.MyCallbackClass {
        void myCallbackMethod(java.lang.String);
    }
    
    0 讨论(0)
  • 2021-01-03 04:01

    in the example file in the android framework tools (YOUR_ANDROID_DIR/tools/proguard/proguard-android.txt), you can find the following rule:

    # We want to keep methods in Activity that could be used in the XML attribute onClick
    -keepclassmembers class * extends android.app.Activity {
       public void *(android.view.View);
    }
    

    With the comment it's quite explicit.

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