Search code examples
androidobfuscationin-app-billingandroid-r8

How to make Amazon In-App Purchasing (IAP) 2.0 work with Android R8


It took a while after significant revenue loss to find out that Android R8 code shrinker prevents Amazon In-App Purchasing (IAP) 2.0 from working. Android Studio uses R8 by default now. Fortunately, the following in gradle.properties seems to be able to stop R8:

android.enableR8=false

I fear R8 will be mandated in the future, and it will be a disaster. I am trying to find a way to make them compatible. Someone posted a similar question on Amazon's forum that is supposed to be the best place for such questions, but I have a feeling that Amazon has stopped supporting the forum because my recent two questions there have received no response from Amazon.

I have the following in proguard-project.txt that is used by R8

#amazon
-dontwarn com.amazon.**
-keep class com.amazon.** {*;}
-keepattributes *Annotation*
-optimizations !code/allocation/variable
-optimizationpasses 1

As my understanding, R8 ignores optimizationpasses. I suspect that is the cause.

Edit(2019-05-30) The aforementioned script for proguard-project.txt is from Amazon's document for In-App Purchasing The app's build.gradle has the following:

release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
    signingConfig signingConfigs.Release

}

Solution

  • proguard-android.txt uses -dontoptimize, so it shouldn't be optimizing at all with ProGuard or R8, regardless of the number of -optimizationpasses specified. If you are interested, you can see the available default ProGuard files under build/intermediates/proguard-files/. proguard-android-optimize.txt is the one that would allow optimization.

    At this point, given that R8's optimization doesn't seem to be on, I'm not sure if there's much of a workaround. I'd recommend that you file an issue with Google's Issue Tracker, giving as much detail as you can to help them reproduce the issue. They are generally pretty responsive to issues like this.