Butterknife: ButterKnife doesn't work with Proguard Enabled

Created on 12 Nov 2015  ·  4Comments  ·  Source: JakeWharton/butterknife

I'm using ButterKnife and in my release build it always throws a NullPointerException on any views associated with @Bind.

I have put in recommended settings:

I have used the following settings for Butter knife:

First Interation:

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

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

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

Second Iteration:

# Butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

At a loss, I want my code obfuscated with minifyEnabled but can't seem to use ButterKnife with it.

Anytime I turn off minifyEnabled it works fine.

Anyone else have any luck?

EDIT:

I also tried using

packagingOptions {
 exclude 'META-INF/services/javax.annotation.processing.Processor'
}

Most helpful comment

yes, it is -keep class **$$ViewBinder { *; }
Thank you so much

All 4 comments

I have same issue with butterknife:7.0.1. Did you found a solution for this ?

Use this rules https://github.com/JakeWharton/butterknife/blob/master/butterknife/proguard-rules.txt

"Second iteration" used rules for ButterKnife 6.

I guess, you've just misconfigured proguard in your build. Make sure you're using it correctly and you're putting rules to the correct file.

yes, it is -keep class **$$ViewBinder { *; }
Thank you so much

Yes that fixed it!

Was this page helpful?
0 / 5 - 0 ratings