javagoogle-playgoogle-play-servicesclassnotfoundexceptionandroid-unity-plugin

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


I want to implement a Leaderboard in my Android Mobile App using Unity.

I am using:

Google Play Services are being activated successfully (In-App-Purchases work perfect), but I keep getting this error when trying to get the leaderboard feature working:

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

Further (To make it clear: I replaced the app name with 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

and

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]]

...and this leads to:

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

I tried to check the SHA-1 Certificate but didn't know how to check and match Keystore and SHA-1 from Google Play Console on Mac.

This is the Code that is being executed when the scene loads in 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 !!! ");
        }
    });
}

The Leaderboard invoke looks like this:

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();

}

The whole part with the error with a NullReferenceException I cannot understand:

 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 

The expected result would be the Google leaderboard UI popping up when calling ShowLeaderBoard().


Solution

  • I had the same issue for days and just figured it out.

    If you have a special character in your project path name then it will not resolve.

    My project had a folder with the "!" in the path name, I simply renamed the folder and made sure not to use spaces or special characters and it works now!

    I hope this fixes your issue too!