Google Play游戏Unity SDK无法创建GameServices对象

时间:2016-10-25 15:55:14

标签: android unity3d google-play-services

我无法使用Google Play Unity插件登录,此代码之前正在运行,现在它无效。

PlayGamesPlatform.Activate ();
PlayGamesPlatform.Instance.localUser.Authenticate (success => {
if (success) {
    LoginType = LoginType.Google;
    StartCoroutine( WaitForEmail());

} else {
    Debug.LogError ("Cannot Login with Gmail");
    return;
}
});

我更新了Google Play服务库。

enter image description here

这是Adb logcat输出:

10-25 19:16:37.399 17469 17488 D GamesUnitySDK: Performing Android initialization of the GPG SDK
10-25 19:16:37.408 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.games.multiplayer.ParticipantResult>
10-25 19:16:37.409 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.games.multiplayer.ParticipantResult>
10-25 19:16:37.409 17469 17488 E GamesNativeSDK: Can't register class com/google/android/gms/games/multiplayer/ParticipantResult: an exception occurred.
10-25 19:16:37.414 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.nearby.connection.AppIdentifier>
10-25 19:16:37.414 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.nearby.connection.AppIdentifier>
10-25 19:16:37.414 17469 17488 E GamesNativeSDK: Can't register class com/google/android/gms/nearby/connection/AppIdentifier: an exception occurred.
10-25 19:16:37.415 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.nearby.connection.AppMetadata>
10-25 19:16:37.415 17469 17488 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.nearby.connection.AppMetadata>
10-25 19:16:37.416 17469 17488 E GamesNativeSDK: Can't register class com/google/android/gms/nearby/connection/AppMetadata: an exception occurred.
10-25 19:16:37.531 17469 17488 I Unity   : Building GPG services, implicitly attempts silent auth
10-25 19:16:37.531 17469 17488 I Unity   :
10-25 19:16:37.531 17469 17488 I Unity   : (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 42)
10-25 19:16:37.531 17469 17488 I Unity   :
10-25 19:16:37.532 17469 17488 E GamesNativeSDK: Could not register one or more required Java classes.
10-25 19:16:37.595 17469 17488 I Unity   : InvalidOperationException: There was an error creating a GameServices object. Check for log errors from GamesNativeSDK
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.Native.PInvoke.GameServicesBuilder.Build (GooglePlayGames.Native.PInvoke.PlatformConfiguration configRef) [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.Native.NativeClient.InitializeGameServices () [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.Native.NativeClient.Authenticate (System.Action`1 callback, Boolean silent) [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.PlayGamesPlatform.Authenticate (System.Action`1 callback, Boolean silent) [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.PlayGamesPlatform.Authenticate (System.Action`1 callback) [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at GooglePlayGames.PlayGamesLocalUser.Authenticate (System.Action`1 callback) [0x00000] in <filename unknown>:0
10-25 19:16:37.595 17469 17488 I Unity   :   at Controllers.LoginController.OnClickedOnGmail () [0x00000] in <filename unknown>:0

感谢。

2 个答案:

答案 0 :(得分:0)

根据此Github,消息:InvalidOperationException: There was an error creating a GameServices object. Check for log errors from GamesNativeSDK通常表示Android SDK太旧了。您应该更新Google Play服务,Google Repository,Android支持库和Android支持存储库组件。

问题的另一个原因是版本8.4.0与Play服务API版本9.8.0不兼容

以下是Google Play services API的更新版本列表。

有关更多信息,请查看上面的Github链接,了解此类错误的其他解决方案。

答案 1 :(得分:0)

这对我有帮助。

https://github.com/playgameservices/play-games-plugin-for-unity/issues/2217#issuecomment-417619382

可以确认此方法有效

body {
    scroll-snap-type:y mandatory;
}

body.fix {
    display:inline-block;
    width:100%;
}

<script>
    document.body.classList.add('fix');
    setTimeout(function() { document.body.classList.remove('fix'); }, 0);
</script>

是的,更正后,我收到了错误“身份验证失败”

但这是SHA-1的问题。我决定这样做的时间:

open template-AndroidManifest.txt
"\ APP_ID" to "\u003__APP_ID__"
setup GPGS from Unity (press Window/Google Play Services/Setup)

然后在应用程序设置的https://console.developers.google.com/apis/credentials中放入正确的SHA-1。