Increase in ANRs on Google Play with IAP v3

Hi all,

I have seen a huge increase in ANRs with the latest update of my game (from ~0 a day to ~30 a day). For those who don’t know, Google Play reports ANRs (Application Not Responding) and they are basically like crashes except it’s harder to assign blame to one process… (Surprisingly, I notice searching for ANR returns no hits in this forum!)

I don’t really know how to read the ANR report on Google Play, since it appears to just list all threads active when the ANR occurred. I guess theoretically the app could be unresponsive due to 10 minor CPU hogs so it makes sense?

The first two sections of every ANR report look like the text I pasted at the bottom (see especially the bolded text).

I believe it might be the new Google IAP v3 plugin that is causing the problem for the following reasons:

  • it’s at the top of the list in all the ANR reports I looked at (I don’t know if that’s a coincidence)

  • the ANR report says that the main thread is waiting on IAP v3 (see below)

  • IAP v3 is one of only a couple of things I added in the latest build, and the other changes were additional graphics etc.

At the risk of way overreaching, perhaps IAP v3 should not be on the main thread?

These are guesses, but I don’t really have any experience with these error messages, and I don’t really know what to test next. The ANRs do not occur on any of my devices, which makes things more complicated. Does anyone have any experience looking at these ANR reports, or has anyone else seen a spike in ANRs with Google IAP v3? If you recently added IAP v3 it might be worth taking a look at the Crash & ANR report page on Google Play.

“main” prio=5 tid=1 MONITOR
| group=“main” sCount=1 dsCount=0 obj=0x412e9508 self=0x412d0bf0
| sysTid=1308 nice=0 sched=0/0 cgrp=[no-cpu-subsys] handle=1075490608
| schedstat=( 80857696685 47094512722 209678 ) utm=5685 stm=2400 core=1
at com.ansca.corona.Controller$3.run(Controller.java:~721)
- waiting to lock <0x41dd44e8> (a com.ansca.corona.Controller) held by tid=10 (GLThread 5592)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)

"GLThread 5592" prio=5 tid=10 WAIT
| group=“main” sCount=1 dsCount=0 obj=0x41e98c38 self=0x54683ff8
| sysTid=3632 nice=0 sched=0/0 cgrp=[no-cpu-subsys] handle=1421421928
| schedstat=( 6304565412 1241821307 5101 ) utm=514 stm=116 core=1
at java.lang.Object.wait(Native Method)

  • waiting on <0x41edb730> (a java.util.concurrent.atomic.AtomicBoolean)
    at java.lang.Object.wait(Object.java:364)
    at plugin.google.iap.v3.LuaLoader.init(LuaLoader.java:167)
    at plugin.google.iap.v3.LuaLoader.access$1200(LuaLoader.java:34)
    at plugin.google.iap.v3.LuaLoader$InitWrapper.invoke(LuaLoader.java:399)

    at com.ansca.corona.JavaToNativeShim.nativeTapEvent(Native Method)
    at com.ansca.corona.JavaToNativeShim.tapEvent(JavaToNativeShim.java:387)
    at com.ansca.corona.input.RaiseTapEventTask.executeUsing(RaiseTapEventTask.java:43)
    at com.ansca.corona.CoronaRuntimeTaskDispatcher$TaskEvent.Send(CoronaRuntimeTaskDispatcher.java:148)
    at com.ansca.corona.events.EventManager.sendEvents(EventManager.java:87)
    at com.ansca.corona.Controller.updateRuntimeState(Controller.java:281)
    at com.ansca.corona.graphics.opengl.CoronaGLSurfaceView$CoronaRenderer.onDrawFrame(CoronaGLSurfaceView.java:417)
    at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1622)
    at com.ansca.corona.graphics.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1377)

It looks like it’s not just me:

http://forums.coronalabs.com/topic/52285-google-play-v3/?hl=%2Biap+%2Bhang#entry272474

I recreated the hang on a HTC One and it turned out to be store = require(“plugin.google.iap.v3”)

It was “fixed” by adding timer.performWithDelay to add a bit of delay. I am not sure if this fixes all hangs.

I’m surprised nobody else has seen this. I believe IAP v3 will become necessary in January…

Hi @hgbrian,

Which part did you have to queue after a short timer? The require of the plugin or the store.init() call?

Thanks,

Brent

Hi Brent,

sorry – I was unclear. It was the loading of the store screen (as a modal on top of my main menu) that caused the problem. The store.lua module does the require(“plugin.google.iap.v3”). In retrospect maybe I should have moved that to main.lua.

I am not 100% sure it’s not store.init that causes the problem.

Here’s the specific bit of code:

native.showAlert("Sorry!", "Unlock premium games in the store!", {"OK"}) timer.performWithDelay(200, function() show\_store() end)

It’s possible that the coincident native.showAlert() didn’t help either.

I also saw the following in logcat quite consistently before the ANR, and I *think* that it wasn’t present when the store popped up normally. Sorry I am not more sure about this:

V/Corona&nbsp; (27335): \> Class.forName: plugin.google.iap.v3.LuaLoader V/Corona&nbsp; (27335): \< Class.forName: plugin.google.iap.v3.LuaLoader V/Corona&nbsp; (27335): Loading via reflection: plugin.google.iap.v3.LuaLoader I/ActivityManager( 1020): Start proc com.android.vending for service com.android.vending/com.google.android.finsky.billing.iab.InAppBillingService: pid=27428 uid=10066 gids={50066, 3003, 1028, 1015}

I was never 100% sure of what the exact cause was, because there was never a crash, just ANRs on specific devices (one of four android devices i tried, a HTC One), so it was tricky to recreate the right conditions for an ANR.

What’s “show_store()” in the delay function?

I don’t quite understand the workaround. 

Corona should check what’s possibly been blocked in “at plugin.google.iap.v3.LuaLoader.init(LuaLoader.java:167)”???

@hgbrian

After the workaround, you don’t see any ANR about this? not a single time?

It looks like it’s not just me:

http://forums.coronalabs.com/topic/52285-google-play-v3/?hl=%2Biap+%2Bhang#entry272474

I recreated the hang on a HTC One and it turned out to be store = require(“plugin.google.iap.v3”)

It was “fixed” by adding timer.performWithDelay to add a bit of delay. I am not sure if this fixes all hangs.

I’m surprised nobody else has seen this. I believe IAP v3 will become necessary in January…

Hi @hgbrian,

Which part did you have to queue after a short timer? The require of the plugin or the store.init() call?

Thanks,

Brent

Hi Brent,

sorry – I was unclear. It was the loading of the store screen (as a modal on top of my main menu) that caused the problem. The store.lua module does the require(“plugin.google.iap.v3”). In retrospect maybe I should have moved that to main.lua.

I am not 100% sure it’s not store.init that causes the problem.

Here’s the specific bit of code:

native.showAlert("Sorry!", "Unlock premium games in the store!", {"OK"}) timer.performWithDelay(200, function() show\_store() end)

It’s possible that the coincident native.showAlert() didn’t help either.

I also saw the following in logcat quite consistently before the ANR, and I *think* that it wasn’t present when the store popped up normally. Sorry I am not more sure about this:

V/Corona&nbsp; (27335): \> Class.forName: plugin.google.iap.v3.LuaLoader V/Corona&nbsp; (27335): \< Class.forName: plugin.google.iap.v3.LuaLoader V/Corona&nbsp; (27335): Loading via reflection: plugin.google.iap.v3.LuaLoader I/ActivityManager( 1020): Start proc com.android.vending for service com.android.vending/com.google.android.finsky.billing.iab.InAppBillingService: pid=27428 uid=10066 gids={50066, 3003, 1028, 1015}

I was never 100% sure of what the exact cause was, because there was never a crash, just ANRs on specific devices (one of four android devices i tried, a HTC One), so it was tricky to recreate the right conditions for an ANR.

What’s “show_store()” in the delay function?

I don’t quite understand the workaround. 

Corona should check what’s possibly been blocked in “at plugin.google.iap.v3.LuaLoader.init(LuaLoader.java:167)”???

@hgbrian

After the workaround, you don’t see any ANR about this? not a single time?