Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Butterknife @Bind fail in release build (after proguard)

I've been building an Android app using Butterknife and recently upgraded to 7.0.1. I replaced all the @InjectView and ButterKnife.inject usage with the new @Bind feature and have no problems with debug builds but the app crashes on startup for release builds.

If I switch 'minifyEnabled' to false in my build.gradle then I can generate a working release build.

I'm using the proguard configuration thats documented on the Butterknife site but it doesn't appear to be working for me. I'm also using Dagger, Picasso and Flurry in my build.

My proguard-rules.pro contents:

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

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

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

# Dagger
-keepclassmembers,allowobfuscation class * {
    @javax.inject.* *;
    @dagger.* *;
    <init>();
}

-keep class javax.inject.** { *; }
-keep class **$$ModuleAdapter
-keep class **$$InjectAdapter
-keep class **$$StaticInjection
-keep class dagger.** { *; }

# Picaso
-dontwarn com.squareup.okhttp.**

# Flurry
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
like image 672
Karl Nosworthy Avatar asked Jul 07 '15 20:07

Karl Nosworthy


2 Answers

We had similar problems after upgrading to 7.0.1 but we got an ANR instead.

The problem seems to be because we replaced the Butterknife section of Proguard with the new recommended options from the ButterKnife website.

Adding -keepnames class * { @butterknife.Bind *;} to the proguard file has fixed our issues.

like image 197
dzeikei Avatar answered Nov 16 '22 09:11

dzeikei


From the website, http://jakewharton.github.io/butterknife/ this seemed to work for me:

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

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

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}
like image 40
Swati Pardeshi Avatar answered Nov 16 '22 08:11

Swati Pardeshi