I added ProGuard to my Android project using default settings, and it broke my code.
On the first screen, I have a Button like this:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onSaveButtonClick" />
And I have a method in the Class:
public void onSaveButtonClick(View view){
// some code
}
When ProGuard disabled, everything works just fine. When enabled, on clicking the button I get this error:
05-17 16:04:54.099: E/AndroidRuntime(1181):
java.lang.IllegalStateException: Could not find a method
onSaveButtonClick(View) in the activity class xxxx for onClick handler
on view class android.widget.Button with id ‘xxxxx’
Any ideas why this happened?
Proguard is changing your method “onSaveButtonClick” to something like “a”. It doesn’t update your XML file so Android can no longer find it. You should either set your click handler programmatically (using setOnClickListener on the view) or following the advice in the linked in SO question that Keyser posted.