Google 使用 Unity 2018 播放服务排行榜时出错(java.lang.ClassNotFoundException:com.google.games.bridge.TokenFragment)

Google Play Service Leadrboard Error using Unity 2018 (java.lang.ClassNotFoundException: com.google.games.bridge.TokenFragment)

我想使用 Unity 在我的 Android 移动应用程序中实现排行榜。

我正在使用:

Google Play 服务已成功激活(应用内购买完美运行),但我在尝试让排行榜功能正常运行时不断收到此错误:

java.lang.ClassNotFoundException: com.google.games.bridge.TokenFragment

进一步(为了清楚起见:我将应用名称替换为 XXXX):

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.games.bridge.TokenFragment" on path: DexPathList[[zip file "/data/app/com.NGDD.XXXX-1/base.apk"],nativeLibraryDirectories=[/data/app/com.NGDD.XXXX-1/lib/arm, /data/app/com.NGDD.XXXX

2019-01-01 17:48:52.784 15145-15145/com.NGDD.XXXX W/System: ClassLoader referenced unknown path: /system/framework/QPerformance.jar
2019-01-01 17:48:52.785 15145-15145/com.NGDD.XXXX E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /vendor/lib]]

...这导致:

*** [Play Games Plugin DLL] 01/01/19 17:51:50 +01:00 ERROR: ShowLeaderboardUI can only be called after authentication.

我尝试检查 SHA-1 证书,但不知道如何检查和匹配来自 Google Play Console on Mac 的 Keystore 和 SHA-1。

这是场景在 Unity 中加载时正在执行的代码:

void ActivateGooglePlayServices()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken().Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();
    LoginToGooglePlay();

}

public void LoginToGooglePlay()
{
    ((PlayGamesPlatform)Social.Active).localUser.Authenticate((bool success) =>
    {
        if (success)
        {
            Debug.Log("!!! Login Success !!!");
        }
        else
        {
            Debug.Log("!!! login failed !!! ");
        }
    });
}

排行榜调用如下所示:

public void ShowLeaderBoard()
{
    // this didn't work at all: --> ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI (leaderboard_ID);
    // The following line throws: *** [Play Games Plugin DLL] 01/01/19 17:51:50 +01:00 ERROR: ShowLeaderboardUI can only be called after authentication.
    Social.ShowLeaderboardUI();

}

我无法理解带有 NullReferenceException 错误的整个部分:

 2019-01-01 18:00:56.564 16197-16236/com.NGDD.XXXX W/Unity: *** [Play Games Plugin DLL] 01/01/19 18:00:56 +01:00 ERROR: UnityEngine.AndroidJavaException: java.lang.ClassNotFoundException: com.google.games.bridge.TokenFragment
java.lang.ClassNotFoundException: com.google.games.bridge.TokenFragment
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:400)
    at java.lang.Class.forName(Class.java:326)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.c(Unknown Source)
    at com.unity3d.player.UnityPlayer$e.queueIdle(Unknown Source)
    at android.os.MessageQueue.next(MessageQueue.java:392)
    at android.os.Looper.loop(Looper.java:136)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.games.bridge.TokenFragment" on path: DexPathList[[zip file "/data/app/com.NGDD.XXXX-2/base.apk"],nativeLibraryDirectories=[/data/app/com.NGDD.XXXX-2/lib/arm, /data/app/com.NGDD.XXXX
2019-01-01 18:00:56.613 16197-16805/com.NGDD.XXXX W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
2019-01-01 18:00:56.613 16197-16805/com.NGDD.XXXX W/google-breakpad: Chrome build fingerprint:
2019-01-01 18:00:56.613 16197-16805/com.NGDD.XXXX W/google-breakpad:71.0.3578.99
2019-01-01 18:00:56.613 16197-16805/com.NGDD.XXXX W/google-breakpad:357809952
2019-01-01 18:00:56.613 16197-16805/com.NGDD.XXXX W/google-breakpad:### ### ### ### ### ### ### ### ### ### ### ### ###
2019-01-01 18:00:56.614 16197-16805/com.NGDD.XXXX E/mono: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at UnityEngine.AndroidJavaObject.Dispose (Boolean disposing) [0x00007] in /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:230 
  at UnityEngine.AndroidJavaObject.Finalize () [0x00003] in /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:225 

预期的结果是 Google 排行榜 UI 在调用 ShowLeaderBoard() 时弹出。

几天来我一直遇到同样的问题,现在才弄明白。

如果您的项目路径名中有特殊字符,则无法解析。

我的项目有一个带有“!”的文件夹在路径名中,我简单地重命名了文件夹并确保不使用空格或特殊字符,它现在可以工作了!

希望这也能解决您的问题!