android - Butterknife 不能在启用 Proguard 的情况下使用,使用推荐的 proguard 规则

标签 android proguard butterknife

我用过ButterKnife在我的发布版本中,它总是抛出 NullPointerException在与 @Bind 相关的任何 View 上.

我已经输入了推荐的设置:

我对 butterknife 使用了以下设置:

第一次互动 :

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
     @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

第二次迭代:
# Butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

不知所措,我想用 minifyEnabled 混淆我的代码但似乎无法使用ButterKnife用它。

任何时候我关闭minifyEnabled它工作正常。

其他人有运气吗?

最佳答案

使用最新版本的 butterknife

http://jakewharton.github.io/butterknife/

编译'com.jakewharton:butterknife:7.0.1'

正如 所述 jack 沃顿

一定要在你的 build.gradle 中禁止这个 lint 警告。

   lintOptions {
      disable 'InvalidPackage'
   }

某些配置可能还需要其他排除项。
   packagingOptions {
     exclude 'META-INF/services/javax.annotation.processing.Processor'
   }

然后尝试我希望它会工作。

关于android - Butterknife 不能在启用 Proguard 的情况下使用,使用推荐的 proguard 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33663162/

相关文章:

Android Studio 禁用 "Expected resource of type string"

android - ImageView AlignParentBottom

android - 导出使用 Proguard 的应用程序时出错

android - Proguard收缩导致空指针异常

java - Android Butterknife - 添加/删除 OnTextChanged 内的 OnTextChangedListener

android - java.lang.illegalStateException : Butterknife 错误

iphone - 制作跨所有操作系统的电话应用程序

安卓设备镜像PC

android - 获取 CursorIndexOutOfBoundsException 错误

maven - 工作 maven 混淆示例