Do not optimize a specific class path with Proguard
I try to implement Amazon In App Purchase in my android application. Amazons documentation requires to specify -dontoptimize in the proguard rules.
The -dontoptimize rule is a global option which will turn off all optimization, but I do want to optimize the other code. So my question is how to specify the proguard rules to only not optimize the Amazon iap code?
It seems that the -keep rule is not enough. This question is related to this SO answer but I am asking for a way to keep the optimizations for the rest of the code while allowing Amazon IAP to work.
You can limit the "do not" optimize by filter: -optimizations !code/allocation/variable
The reason of why Amazon IAP requires -dontoptimize is a little bit tricky.
First, Amazon IAP documentation requires -dontwarn com.amazon.**.
If you remove it, you will see the proguard complain that it can not find reference to some class in the package: com.amazon.android. and com.amazon.venezia..
So it proves that amazon in-app-purchasing-1.0.7.jar has an external dependent jar.
Now here is a problem. When proguard executes the optimization task. It needs to know all the dependent libraries in order to do proper optimization (e.g. remove never used method, useless parameters etc.).
While in this case proguard does not know the external dependent amazon jar, it will do some wrong optimizations for the in-app-purchasing-1.0.7.jar.
This is also why Amazon requires -dontoptimize.
This sounds a bug of proguard. But unfortunately this issue exists even you update to the latest proguard (5.0).