playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 967 forks source link

InvalidOperationException: There was an error creating a GameServices object. Check for log errors from GamesNativeSDK #2562

Open sayiliromer opened 5 years ago

sayiliromer commented 5 years ago

We are having this issue since we updated gpg plugin version to 0.9.62 and switched scripting backend to il2cpp. currently we are using 0.9.63. and still having same issue. Unity diagnostics dashboard is full of that exception.

It is not always happening. Sometimes it is working without issue

GooglePlayGames.Native.PInvoke.GameServicesBuilder.Build (GooglePlayGames.Native.PInvoke.PlatformConfiguration configRef) (at <00000000000000000000000000000000>:0)
GooglePlayGames.Native.NativeClient.InitializeGameServices () (at <00000000000000000000000000000000>:0)
GooglePlayGames.Native.NativeClient+<>c__DisplayClass21_0.<Authenticate>b__0 (System.Int32 result) (at <00000000000000000000000000000000>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <00000000000000000000000000000000>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <00000000000000000000000000000000>:0)
UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0)
Rethrow as TargetInvocationException: GooglePlayGames.Android.AndroidTokenClient+ResultCallbackProxy.onResult(UnityEngine.AndroidJavaObject)
UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0)
UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) (at <00000000000000000000000000000000>:0)
olehkuznetsov commented 5 years ago

Do you have proguard enabled?

sayiliromer commented 5 years ago

It is disabled in the player settings. But i am not sure if something is overriding it in some place. Is there any way that i can be sure ?

sayiliromer commented 5 years ago

We are using custom gradle template, here it is mainTemplate.txt image

olehkuznetsov commented 5 years ago

Can you try to create a new project and use it with Minimal sample from https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/samples folder, please? You can use the Play Games setup from your project - just copy 'Window->Google Play Games->Setup->Android Setup' window content.

sayiliromer commented 5 years ago

Can you try to create a new project and use it with Minimal sample from https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/samples folder, please? You can use the Play Games setup from your project - just copy 'Window->Google Play Games->Setup->Android Setup' window content.

I am gonna try it, but it is hard to reproduce. I experienced it only once

sayiliromer commented 5 years ago

@olehkuznetsov All right. I have an update for this issue. It is most probably a unity bug. Finally i am able to reproduce it. If you quit app with Application.Quit() (Which is most probably with back button) application throws some exceptions

android.app.IntentReceiverLeaked: Activity com.unity3d.player.UnityPlayerActivity has leaked IntentReceiver com.unity.purchasing.googleplay.GooglePlayPurchasing$4@56ef208 that was originally registered here. Are you missing a call to unregisterReceiver()?

android.app.ServiceConnectionLeaked: Activity com.unity3d.player.UnityPlayerActivity has leaked ServiceConnection null that was originally bound here

etc.

And after that. If you relaunch app again. It fails to initialize gpg plugin with that exception

InvalidOperationException: There was an error creating a GameServices object. Check for log errors from GamesNativeSDK

But if you kill app from Overview screen or application manager. Everything works fine. My workaround for the issue is when you press back button, Instead of killing app, now i am dropping into background.

Here some reports about the bug https://issuetracker.unity3d.com/issues/activity-has-leaked-serviceconnection-errors-when-calling-application-dot-unload

https://forum.unity.com/threads/crash-with-back-button.605983/

https://forum.unity.com/threads/activity-io-branch-unity-branchunityactivity-has-leaked-intentreceiver-com-unity-purchasing-googlepl.652372/

cmeil commented 5 years ago

@sayiliromer I can consistently reproduce this on a Samsung S III running Android 4.4.4, and I tried with Unity 2019.1.3f1, which has the fix to issue 1091255, but the InvalidOperationException on the GamesService object still occurs.

I also noted that after waiting overnight, a second authentication attempt worked without the error, so there's apparently some time-out at some point. This might explain why the problem is intermittent.

cmeil commented 5 years ago

More info on my case: When connected to logcat, I also see this error: E/GamesNativeSDK: Can only create one instance of GameServices at a time.

cactus171 commented 5 years ago

i had same case with unity 2018.4.2f and 0.9.64

BrokenHell commented 5 years ago

I have same error , did anyone can fix this ?

rubenaster commented 5 years ago

Same here with Unity 2019.1.6f1.. Unity already announced to fix this but they don't commit to a version or date :-/

cmeil commented 5 years ago

Same here with Unity 2019.1.6f1.. Unity already announced to fix this but they don't commit to a version or date :-/

@rubenaster What fix did Unity announce for this? Link?

rubenaster commented 5 years ago

@cmeil They are currently fixing the leakage of Activities: https://forum.unity.com/threads/android-2018-3-13-unitypurchasing-dont-initialize-after-application-quit.665497/#post-4646566

Tanek81 commented 5 years ago

I fixed this Unity issue with this workaround: https://forum.unity.com/threads/android-2018-3-13-unitypurchasing-dont-initialize-after-application-quit.665497/#post-4595101 Our internal tests are positive, we are going to release this in Beta soon to see if there is any issue with any specific device.

Please be advised that https://issuetracker.unity3d.com/issues/activity-has-leaked-serviceconnection-errors-when-calling-application-dot-unload is not related to this issue and/or it is not really fixed in 2019.1: we were "fooled" by that "fixed in 2019.1" tag and we updated Unity from 2018.4 to 2019.1 in order to fix this issue which instead still persisted. I am evaluating if we should revert to 2018.4 or keep going with 2019.1.

cactus171 commented 5 years ago

This solution looks good

new AndroidJavaClass("java.lang.System").CallStatic("exit", 0);
Application.Quit();

https://forum.unity.com/threads/android-2018-3-13-unitypurchasing-dont-initialize-after-application-quit.665497/page-2#post-4805402

cmeil commented 5 years ago

Unity has fixed this now (https://forum.unity.com/threads/solved-android-2018-3-13-unitypurchasing-dont-initialize-after-application-quit.665497/page-2)

Leuconoe commented 4 years ago

Unity has fixed this now (https://forum.unity.com/threads/solved-android-2018-3-13-unitypurchasing-dont-initialize-after-application-quit.665497/page-2)

I have same problem in 2018.3.14. It is resolved in 2019.3.