Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException in Google Play Game Service doesn't make sense

I have a game in the Play Market and I got the message and stacktrace back.

java.lang.IllegalStateException
Msg: (Not connected. Call connect() and wait for onConnected() to be called.)

java.lang.IllegalStateException
com.google.android.gms.internal.p.n(Unknown Source)
com.google.android.gms.internal.p.o(Unknown Source)
com.google.android.gms.internal.e.loadState(Unknown Source)
com.google.android.gms.appstate.AppStateClient.loadState(Unknown Source)
com.peerkesoftware.blockcrusher.CloudSave.load(CloudSave.java:31)
com.peerkesoftware.blockcrusher.CloudSave.setAppStateClient(CloudSave.java:26)
com.peerkesoftware.blockcrusher.MorburActivity.onSignInSucceeded(MorburActivity.java:475)
com.peerkesoftware.libgeneric.app.game.GameHelper.succeedSignIn(GameHelper.java:652)
com.peerkesoftware.libgeneric.app.game.GameHelper.connectNextClient(GameHelper.java:539)
com.peerkesoftware.libgeneric.app.game.GameHelper.onConnected(GameHelper.java:642)
com.google.android.gms.internal.p.k(Unknown Source)
com.google.android.gms.internal.bj.k(Unknown Source)
com.google.android.gms.internal.p$f.a(Unknown Source)
com.google.android.gms.internal.p$f.a(Unknown Source)
com.google.android.gms.internal.p$b.p(Unknown Source)
com.google.android.gms.internal.p$a.handleMessage(Unknown Source)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:132)
android.app.ActivityThread.main(ActivityThread.java:4126)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:491)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
dalvik.system.NativeStart.main(Native Method)

The strange thing is the message saying that the I should call connect() and wait for the onConnected(). But as you can see in the stacktrace the call is coming from the onConnected(). So I know for sure Google Play Services is connected. Why do I still get the IllegalStateException? I doesn't make sense.

like image 348
Peter Fortuin Avatar asked Oct 03 '22 20:10

Peter Fortuin


1 Answers

There are cases where android.gms.internal throws IllegalStateException even when you use the API correctly. E.g. the trace below logs that all the clients connect and it is while handling google's succeedSignIn() callback to our code that we get that exception. (SwGameHelper is our copy of google's GameHelper code)

Note that the gms.internal stack trace appears to include some methods with the name "signOut". So this could be a bug with the google code, but my guess is it's a race condition where the connection is being lost immediately after connection. I have had to deal with similar races on other connected services. If it's a race google may just need to document better that this exception can be thrown by their methods even if you were connected when you called them.

I'm considering work-arounds where we catch this. I'll update if I find a good fix.

This is one of our most common crashing bugs with installed customers so it's not that rare.

onConnected: connected! client=1 com.lootworks.swords.screens.SwGameHelper
Connecting PlusClient. com.lootworks.swords.screens.SwGameHelper
onConnected: connected! client=2 com.lootworks.swords.screens.SwGameHelper
All clients now connected. Sign-in successful. com.lootworks.swords.screens.SwGameHelper
All requested clients connected. Sign-in succeeded! com.lootworks.swords.screens.SwGameHelper

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
    at com.google.android.gms.internal.p.n(Unknown Source)
    at com.google.android.gms.internal.p.o(Unknown Source)
    at com.google.android.gms.internal.bj.a(Unknown Source)
                                       loadAchievements
                                       b
                                       a
                                       signOut
                                       a
                                       a
    at com.google.android.gms.games.GamesClient.loadAchievements(Unknown Source)
                                             signOut
    at com.lootworks.swords.social.SwAchievementManager.loadAndUploadAchievements(SourceFile:441)
    at com.lootworks.swords.activity.SwMap3D.onSignInSucceeded(SourceFile:3526)
    at com.lootworks.swords.screens.SwGameHelper.succeedSignIn(SourceFile:639)
    at com.lootworks.swords.screens.SwGameHelper.connectNextClient(SourceFile:530)
    at com.lootworks.swords.screens.SwGameHelper.onConnected(SourceFile:629)
    at com.google.android.gms.internal.p.k(Unknown Source)
    at com.google.android.gms.internal.bj.k(Unknown Source)
    at com.google.android.gms.internal.p$f.a(Unknown Source)
    at com.google.android.gms.internal.p$f.a(Unknown Source)
    at com.google.android.gms.internal.p$b.p(Unknown Source)
    at com.google.android.gms.internal.p$a.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:99)
like image 198
mwk Avatar answered Oct 13 '22 11:10

mwk