android - ProGuard 破坏了我的 Android 代码

标签 android proguard

我使用默认设置将 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/

相关文章:

安卓 : how can I store an audio file in the application folder

android - 如何在 fragment 中使用 Parcelable 获取数据?

android - AdMob 横幅广告未展示

java - 在多模块项目上运行 Proguard 作为 "one piece"

android - 如何使用 Ant 构建 Android 项目? (智能集成开发环境)

java - 按钮不执行正确的命令[编辑]

android - 渲染布局文件和预览问题

android - 在 Eclipse 中使用 ProGuard(没有私钥)

android - Gradle中的dex是什么

android - 更新到 Google Play 服务 11.8.0 后 Proguard 不工作