我使用默认设置将 ProGuard 添加到我的 Android 项目中,但它破坏了我的代码。
在第一个屏幕上,我有一个像这样的按钮:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onSaveButtonClick" />
我在类中有一个方法:
public void onSaveButtonClick(View view){
// some code
}
当 ProGuard 禁用时,一切正常。启用后,单击按钮时出现此错误:
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'
知道为什么会发生这种情况吗?
最佳答案
Proguard 正在将您的方法“onSaveButtonClick”更改为类似“a”的内容。它不会更新您的 XML 文件,因此 Android 无法再找到它。您应该以编程方式设置点击处理程序(在 View 上使用 setOnClickListener)或遵循 Keyser 发布的 SO 问题链接中的建议。
关于android - ProGuard 破坏了我的 Android 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10642931/