Codename one IAP Fails on Android

We've been developing an app centered around in app purchases.
I've followed the guide here;

https://www.codenameone.com/blog/intro-to-in-app-purchase.html

And implemented the purchases in the following way;

public static boolean brought(String sku) {
    try{
        boolean brought = Purchase.getInAppPurchase().wasPurchased(sku);
        return brought;
    }catch(Exception e){
    }
    return false;//error
}

public static void buy(String sku){
    Purchase.getInAppPurchase().purchase(sku);
}

The purchases have been correctly setup with google play but when the "Buy dialog" is completed the app crashes with the following error/stack trace (taken from the google play console);

java.lang.RuntimeException:  
  at android.app.ActivityThread.deliverResults (ActivityThread.java:3736)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:3779)
  at android.app.ActivityThread.access$1400 (ActivityThread.java:157)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1406)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:148)
  at android.app.ActivityThread.main (ActivityThread.java:5459)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)
Caused by: java.lang.IllegalArgumentException: 
  at com.codename1.payments.v3.Security.generatePublicKey (Security.java:90)
  at com.codename1.payments.v3.Security.verifyPurchase (Security.java:67)
  at com.codename1.payments.v3.IabHelper.handleActivityResult (IabHelper.java:480)
  at com.codename1.impl.android.CodenameOneActivity.onActivityResult (CodenameOneActivity.java:537)
  at android.app.Activity.dispatchActivityResult (Activity.java:6470)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:3732)
Caused by: com.codename1.impl.android.util.Base64DecoderException: 
  at com.codename1.impl.android.util.Base64.decode (Base64.java:546)
  at com.codename1.impl.android.util.Base64.decode (Base64.java:474)
  at com.codename1.impl.android.util.Base64.decode (Base64.java:420)
  at com.codename1.payments.v3.Security.generatePublicKey (Security.java:80)

Then after a purchase has been made any call to

Purchase.getInAppPurchase().wasPurchased(sku)

seems to lock the app and freeze the UI with no errors to the log.

I'm fairly sure this used to work since we've used this in the past.

Upvotes: 0

Views: 66

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

Make sure that you've set the android.licenseKey build hint to the correct String from the google play console. This exception is triggered when we try to parse the base64 value from Google to verify the purchase. If you just set it to a blank value or have an extra character in place that can fail.

Upvotes: 1

Related Questions