libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

Crash on some relaunches of app - only if Android system removes from memory #164

Closed slush1000 closed 6 years ago

slush1000 commented 6 years ago

I have implemented gdx-pay using the Integration Example and everything seems to work as it should. A simple entitlement purchase.

The issue I am having is when the app is relaunched it will crash sometimes. It seems to only happen if the app is not exited through the app but instead removed by Android for memory maintenance. (Edit: I am finding out that it does seem to happen even after exiting through the app.) I can only make it happen on my Pixel 2 after more than at least 4 hours.

I invoke this by not exiting the app but either switching apps or by swiping the app away after tapping the Android overview button waiting a few hours and open the app again. This happens with more frequency on a friends Nexus 5x.

02-15 18:34:32.712 7434-7461/ca.raisemewell.numbers E/AndroidRuntime: FATAL EXCEPTION: GLThread 8619
       Process: ca.raisemewell.numbers, PID: 7434
       com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.pay.android.googleplay.GdxPayException: Unexpected exception in getPurchases()
           at ca.raisemewell.numbers.NumbersMain$1.handleRestoreError(NumbersMain.java:58)
           at com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager.purchaseRestore(AndroidGooglePlayPurchaseManager.java:266)
           at com.badlogic.gdx.pay.PurchaseSystem.purchaseRestore(PurchaseSystem.java:157)
           at ca.raisemewell.numbers.PlatformResolver.requestPurchaseRestore(PlatformResolver.java:58)
           at ca.raisemewell.numbers.Screens.ScreenLoading.<init>(ScreenLoading.java:68)
           at ca.raisemewell.numbers.NumbersMain.create(NumbersMain.java:120)
           at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
           at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
           at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
        Caused by: com.badlogic.gdx.pay.android.googleplay.GdxPayException: Unexpected exception in getPurchases()
           at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.getPurchases(V3GoogleInAppBillingService.java:351)
           at com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager.purchaseRestore(AndroidGooglePlayPurchaseManager.java:249)
           at com.badlogic.gdx.pay.PurchaseSystem.purchaseRestore(PurchaseSystem.java:157) 
           at ca.raisemewell.numbers.PlatformResolver.requestPurchaseRestore(PlatformResolver.java:58) 
           at ca.raisemewell.numbers.Screens.ScreenLoading.<init>(ScreenLoading.java:68) 
           at ca.raisemewell.numbers.NumbersMain.create(NumbersMain.java:120) 
           at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275) 
           at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555) 
           at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270) 
        Caused by: com.badlogic.gdx.pay.android.googleplay.GdxPayException: Not connected to Google In-app Billing service
           at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.billingService(V3GoogleInAppBillingService.java:387)
           at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.getPurchases(V3GoogleInAppBillingService.java:341)
           at com.badlogic.gdx.pay.android.googleplay.AndroidGooglePlayPurchaseManager.purchaseRestore(AndroidGooglePlayPurchaseManager.java:249) 
           at com.badlogic.gdx.pay.PurchaseSystem.purchaseRestore(PurchaseSystem.java:157) 
           at ca.raisemewell.numbers.PlatformResolver.requestPurchaseRestore(PlatformResolver.java:58) 
           at ca.raisemewell.numbers.Screens.ScreenLoading.<init>(ScreenLoading.java:68) 
           at ca.raisemewell.numbers.NumbersMain.create(NumbersMain.java:120) 
           at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275) 
           at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555) 
           at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270) 
02-15 18:34:32.763 7434-7434/ca.raisemewell.numbers I/AndroidInput: sensor listener tear down

I really need some advise with this one.

gdxVersion = '1.9.6'
roboVMVersion = '2.3.2'
gdxPayVersion = '0.11.2'
slush1000 commented 6 years ago

I dumped GDX-pay and implemented Android IAP another way. I'll implement IOS separately too. Is GDX-pay a dead project?

keesvandieren commented 6 years ago

It is not dead, we are using it in production.

handleRestoreError (and other handle*Error methods) should not continue to throw the Exception. They can happen without doing something wrong in the app, e.g. when someone installs the app on Android phone that has no Google Play Store installed, or when someone stops the Google Play Services via Applications, and probably as wel on garbage collection.

For users still using gdx-pay: