Search code examples
androidlibgdxgdx-pay

GdxPay "onPurchaseHistoryResponse failed with responseCode -1"


Here's how I setup the purchase manager in my AndroidLauncher onCreate method (using libgdx 1.9.6 and gdxpay 0.11.3):

purchaseManager = new PurchaseManagerGoogleBilling(this);
PurchaseManagerConfig pmc = new PurchaseManagerConfig();
pmc.addStoreParam(PurchaseManagerConfig.STORE_NAME_ANDROID_GOOGLE, base64EncodedPublicKey);
pmc.addOffer(new Offer().setType(OfferType.ENTITLEMENT).setIdentifier(globals.skuFullVer));

myPurchaseObserver = new MyPurchaseObserver(globals, highScores);
purchaseManager.install(myPurchaseObserver, pmc, true);

purchaseManager.purchaseRestore();  

However, when purchaseRestore() is called, I get the following exception:

FATAL EXCEPTION: main
Process: com.eb.droid, PID: 8823
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eb.droid/com.eb.droid.android.AndroidLauncher}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.badlogic.gdx.Application.error(java.lang.String, java.lang.String)' on a null object reference
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2491)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564)
  at android.app.ActivityThread.access$800(ActivityThread.java:170)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441)
  at android.os.Handler.dispatchMessage(Handler.java:111)
  at android.os.Looper.loop(Looper.java:194)
  at android.app.ActivityThread.main(ActivityThread.java:5576)
  at java.lang.reflect.Method.invoke(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.badlogic.gdx.Application.error(java.lang.String, java.lang.String)' on a null object reference
  at com.badlogic.gdx.pay.android.googlebilling.PurchaseManagerGoogleBilling$4.onPurchaseHistoryResponse(PurchaseManagerGoogleBilling.java:197)
  at com.android.billingclient.api.BillingClientImpl.queryPurchaseHistoryAsync(BillingClientImpl.java:477)
  at com.badlogic.gdx.pay.android.googlebilling.PurchaseManagerGoogleBilling.purchaseRestore(PurchaseManagerGoogleBilling.java:191)
  at com.eb.droid.android.AndroidLauncher.onCreate(AndroidLauncher.java:141)
  at android.app.Activity.performCreate(Activity.java:6041)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2564) 
  at android.app.ActivityThread.access$800(ActivityThread.java:170) 
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1441) 
  at android.os.Handler.dispatchMessage(Handler.java:111) 
  at android.os.Looper.loop(Looper.java:194) 
  at android.app.ActivityThread.main(ActivityThread.java:5576) 
  at java.lang.reflect.Method.invoke(Native Method) 
  at java.lang.reflect.Method.invoke(Method.java:372) 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751) 

When I debug the PurchaseManagerGoogleBilling.java purchaseRestore method, the responseCode returns -1 and the purchase object is null, and the following error is reported via Gdx:

onPurchaseHistoryResponse failed with responseCode -1  

Note that I call initialize in AndroidLauncher > onCreate AFTER I setup the PurchaseManager.

Anyone have any pointers for what is going wrong here? I had payments fulling working with the old IabHelper, but I've switched to GdxPay as it uses the newer BillingLibrary with is supposed to be more stable. Also, I'm only targeting Android.


Solution

  • Problem was asked and solved here: https://www.reddit.com/r/libgdx/comments/9c28gt/gdxpay_onpurchasehistoryresponse_failed_with/