我想使用 Unity 在我的 Android 移动应用中实现排行榜。
我在用:
Unity 2018.2.18f1 (Mac)
Java 开发工具包 (jdk.1.8.0_191)
Google Play 游戏插件 0.9.57 [当前版本 1.1.2019]
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.
- 我尝试了不同的构建类型(内部和 gradle)。
- 我在 Google Play 上为内部和 Alpha 测试人员发布了该应用程序,并将设备的 google 帐户设置为测试帐户
我尝试检查 SHA-1 证书,但不知道如何从 Mac 上的 Google Play 控制台检查和匹配 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$2.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
预期的结果是调用 ShowLeaderBoard() 时弹出的 Google 排行榜 UI。