I am running ButterKnife version 8.5.1 in my Android app. If I try to make ProGuard settings for ButterKnife I still got crashes in my release version. There is an issue on the official ButterKnife Github page which tells you to make the following settings:
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
Alternatively it is written to use these settings:
# Butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
None of these work with my configuration. I still got crashes when accessing Views bound by ButterKnife. So are there any new settings which you need to make for ButterKnife 8?
Go to Gradle Scripts and then look for a file called proguard-rules.pro and there you can edit it. The proguard-rules.pro file is where you can add custom ProGuard rules. By default, this file is located at the root of the module (next to the build. gradle file).
ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.
In ButterKnife 8 the auto generated Subclasses are called different. You can handle ProGuard settings for Version 7 and 8 this way:
###---------------Begin: proguard configuration for ButterKnife ----------
# For Butterknife:
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
# Version 7
-keep class **$$ViewBinder { *; }
# Version 8
-keep class **_ViewBinding { *; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
###---------------End: proguard configuration for ButterKnife ----------
Although I am using @OnClick
methods I even do not need the last line. These settings work perfect for me. Try it out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With