Do not optimize a specific class path with Proguard

狂风中的少年 提交于 2019-12-07 19:23:30

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/26061795/do-not-optimize-a-specific-class-path-with-proguard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!