How to set up ProGuard for Amazon IAP?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 10:54:41

问题


I'm trying to set up a basic ProGuard with Amazon IAP integrated. However when I'm trying to export my APK, I got the following errors:

[2012-06-17 10:59:44 - sc] Proguard returned with error code 1. See console
[2012-06-17 10:59:44 - sc] Unexpected error while performing partial evaluation:
[2012-06-17 10:59:44 - sc]   Class       = [com/amazon/inapp/purchasing/KiwiResponseHandler$PurchaseResponseHandlerRunnable]
[2012-06-17 10:59:44 - sc]   Method      = [run()V]
[2012-06-17 10:59:44 - sc]   Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [java/lang/String] (with 4 known super classes) and [com/amazon/inapp/purchasing/KiwiPurchaseResponseCommandTask] (with 1 known super classes))
[2012-06-17 10:59:44 - sc] java.lang.IllegalArgumentException: Can't find common super class of [java/lang/String] (with 4 known super classes) and [com/amazon/inapp/purchasing/KiwiPurchaseResponseCommandTask] (with 1 known super classes)
[2012-06-17 10:59:44 - sc]  at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:344)
[2012-06-17 10:59:44 - sc]  at proguard.evaluation.value.IdentifiedReferenceValue.generalize(IdentifiedReferenceValue.java:65)
[2012-06-17 10:59:44 - sc]  at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:481)
...

I have the default ProGuard configuration file, and I have already added the:

 -dontwarn com.amazon.**
 -keep class com.amazon.** {*;}
 -keepattributes *Annotation*

lines to it. Any suggestion what went wrong?


回答1:


There is some fishy stuff with the recommended config of Amazon.

1) -dontwarn is hiding a deeper underlying issue, where some Amazon specific libraries are not present, but referenced so that proguard will try some wired optimization which likely causes the above mentioned stacktrace.

2) -dontoptimize is disabling all optimizations, which is defenitivly wrong, because it is most probably just one specific optimization which is causing this issue, and proguards optimizations are removing alot of dead and unused code from your app and its libraries, so it shrinks the total dex size.

I guess fixing 1) is the real solution. This could be eventually achieved by extracting Amazons system libs from a device and make them present (as a provided lib) while building
the app.

For 2) you can try:

-dontwarn com.amazon.**
-keep class com.amazon.** {
    *;
}

-optimizations !code/allocation/variable

which solved the issue for me.




回答2:


Per Amazon's SDK Docs, here are the lines you should include:

Preventing Obfuscation of In-App Purchasing API

When incorporating the In-App Purchasing API into your library, you will need to specify classes to 'keep' and not obfuscate. Add the following lines anywhere in your proguard.cfg file.

-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*

In addition, you will also need to skip Proguard's optimization step.

-dontoptimize

Note: Make sure to remove any other flags dealing with optimization, or any flag that may conflict with the above settings.




回答3:


In addition, you will also need to lower the number of optimization passes to 1, or skip proguard's optimization step.

-optimizationpasses 1

or

-dontoptimize



来源:https://stackoverflow.com/questions/11070143/how-to-set-up-proguard-for-amazon-iap

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