libgdx / gdx-pay

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

Android: PurchaseSystem.install(...) throws exception #31

Closed wsrdzg closed 9 years ago

wsrdzg commented 9 years ago

If you call PurchaseSystem.install(...) in ApplicationListener.create()/ApplicationAdapter.create() like in the test (https://github.com/libgdx/gdx-pay/blob/master/gdx-pay-tests/src/com/badlogic/gdx/pay/tests/PayTest.java) you get the following exception on Android:

02-07 01:30:50.183  21823-21855/com.example.game E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 877
    Process: com.example.game, PID: 21823
    java.lang.IllegalStateException: Must be called from UI thread.
            at org.onepf.oms.OpenIabHelper.finishSetup(OpenIabHelper.java:896)
            at org.onepf.oms.OpenIabHelper.finishSetup(OpenIabHelper.java:889)
            at org.onepf.oms.OpenIabHelper.finishSetup(OpenIabHelper.java:881)
            at org.onepf.oms.OpenIabHelper.setupWithStrategy(OpenIabHelper.java:539)
            at org.onepf.oms.OpenIabHelper.startSetup(OpenIabHelper.java:519)
            at com.badlogic.gdx.pay.android.openiab.PurchaseManagerAndroidOpenIAB.install(PurchaseManagerAndroidOpenIAB.java:222)
            at com.badlogic.gdx.pay.PurchaseSystem.install(PurchaseSystem.java:168)
            at com.example.game.Main.create(Main.java:124)
            at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:241)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

With version 0.2.0 that doesn't happen.

noblemaster commented 9 years ago

Thanks for the report & stack trace! I update OpenIAB install to be forced to run on the UI thread. That should take care of the problem.

Please use the latest snapshot release to test it; 0.4.0-SNAPSHOT (just pushed to maven).

wsrdzg commented 9 years ago

Thanks after updating to 0.4.0-SNAPSHOT I didn't get the exception. But I get a proguard failure:

Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.MpUtils
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.MpUtils
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentRequest
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentRequest$PaymentRequestBuilder
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentRequest
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.MpUtils
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentRequest$PaymentRequestBuilder
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.MpUtils
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentResponse
Warning:org.onepf.oms.appstore.FortumoBillingService: can't find referenced class mp.PaymentRequest
Warning:there were 31 unresolved references to classes or interfaces.

I got other proguard failures before when I used 0.2.0, so I added following like I had read in on some website:

-keep public class com.badlogic.gdx.Gdx {
  public protected *;
}

-keep public class com.badlogic.gdx.Application {
  public protected *;
}

-keep public class com.badlogic.gdx.pay.android.IAP {
  public protected *;
}

-keep public class com.badlogic.gdx.backends.android.AndroidEventListener {
  public protected *;
}

-keep public class com.badlogic.gdx.backends.android.AndroidApplication {
  public protected *;
}

-keep public class de.darkbloodstudios.foreveralone.AndroidLauncher {
  public protected *;
}

-keep public class com.badlogic.gdx.pay.android.openiab.PurchaseManagerAndroidOpenIAB {
  public protected *;
}

EDIT: I added -dontwarn org.onepf.oms.appstore.FortumoBillingService now it is working. Maybe you can edit the tutorial here on GitHub so others know what to do.

noblemaster commented 9 years ago

Great - Thanks for testing it out! :-D Anyhow, I updated the gdx-pay readme to reflect the changed proguard configuration.