使用 Butterknife 的 Proguard 可防止混淆 class 个名称

Proguard with Butterknife prevents obfuscation of class names

因为 Butterknife 使用反射生成 类 与每个 activityfragment 相关联。由于 Proguard 忽略那些 类 并且不在其规则中混淆它。

找到一个解决方法是使用通过将 ButterKnife.bind(this) 替换为新的 Whatever_ViewBinder(this) 生成 类 的 Butterknife,并在我的代码中使用它们。这确实有效,Progurad 混淆了我的 类。但这里唯一的问题是我必须将它们从 Debug 文件夹复制到我的包中以获取 changed/deleted。每次我 add/remove 观看时更新它。 source

我发现的另一个问题说使用数据绑定更好 。但是我现在更改整个代码已经太晚了

如果您发现了解决此问题的方法,请分享。 我正在使用 Butterknife v8.6.0。如果有帮助的话

您甚至通过 #746 链接到自己的答案。

[...] until I remove all imports of Butter Knife from the class, Proguard doesn't work on it.

这是因为在 9.0 版之前,Proguard 规则是随 Butter Knife 本身一起提供的。

The ProGuard rules will be separated in 9.0 when using the generated code API becomes stable.

所以基本上不可能轻松完成您打算做的事情。最好的办法是 fork Butter Knife 并从 build.gradle 中删除 consumerProguardFiles 定义。然后等9.0版本出来再用原来的。