How to get simple Android (Studio) Proguard config
In every project I previously worked on where Proguard was listed, it was eventually abandoned as it caused so many problems that it was unusable and a huge source of resources. But my current project does require obfuscation to make reverse engineering more difficult. Since I am using Android Studio and Gradle, I included it in my build config:
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
Then I build release build and see 292 warnings and build failures. Most of them are as follows and relate to libraries (Retrofit, Joda Time, Butterknife, etc.)
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.TypeElement
OK, so my guess is that it optimizes parts of the libraries. So I tried to add lines like this to the proguard-rules.pro file (specified in the Gradle file and automatically generated by Android Studio):
-keep class butterknife.internal.** { *; }
No difference. Ok, so I'll try to disable ALL reduction and optimize to hopefully benefit from obfuscation (even if, admittedly, slightly less room for obfuscation). I added this line to the Proguard config file:
-dontshrink
-dontoptimize
I recompile and absolutely nothing changes, I'm still left with 292 pretty pointless compilation warnings. Now I am really confused.
- How can I make Proguard 100% specific by actually looking at my Proguard config file? Or does he use it, but I installed the wrong option?
- What can I add to the Proguard file to reduce it to JUST obfuscation, so I have a Proguard enabled build configuration that works as a starting point (without breaking my application) and doesn't optimize any code.
Any help would be grateful to help reduce my hatred of Progurda.
source to share
add the following to your proguard config so it doesn't overload your library with a knife.
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
here is a link for a github discussion about the same issue, https://github.com/JakeWharton/butterknife/pull/117#issuecomment-51292624
source to share