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

2

11

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.**
Boater answered 7/7, 2015 at 20:34 Comment(0)
U
11

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.

Unreflecting answered 8/7, 2015 at 6:43 Comment(0)
M
7

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>;
}
Malchus answered 8/9, 2015 at 5:53 Comment(1)
this official from jakeJelene

© 2022 - 2024 — McMap. All rights reserved.