Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto configure ProGuard settings for ButterKnife 8?

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?

like image 904
unlimited101 Avatar asked Mar 24 '17 14:03

unlimited101


People also ask

Where is ProGuard config file?

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).

What is ProGuard configuration?

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.


1 Answers

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!

like image 83
unlimited101 Avatar answered Oct 17 '22 02:10

unlimited101