playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.43k stars 954 forks source link

Trying Signin failure (PlayGamesPlatform.Instance.Authenticate, Social.localUser.Authenticate) #3072

Closed geoseong closed 2 years ago

geoseong commented 2 years ago

Hi.

I started to use this plugin from this Monday, and I'm struggling with this problem for 3 days.

I first tried to follow this youtube guide

after following this, it fails.

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.Games

so I fixed that error above

  1. checked Custom Proguard File in Player settings and copy & paste refer to this proguard.txt file to my local proguard.txt. image

after when I tried to signin, the status is always Canceled. so I tried to check Custom Main Manifest in Player settings, it fails.

my code is like this

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using GooglePlayGames.BasicApi;

public class GPGSManager : MonoBehaviour
{
    [SerializeField]
    Text txtSigninStatus;

    [SerializeField]
    Text txtReportScoreStatus;

    string leaderboardID = "_____";

    private void Start()
    {
        InitializeGPGS();
    }

    public void InitializeGPGS()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            .RequestServerAuthCode(false /* Don't force refresh */)
            .EnableSavedGames()
            .Build();

        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();
    }

    public void OnSignInToGooglePlayGamesService()
    {
        // [failed]
        //Social.localUser.Authenticate((result) => {
        //    // handle results
        //    txtSigninStatus.text = result.ToString();
        //});

        // [failed]
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) =>
        {
            // handle results
            txtSigninStatus.text = result.ToString();
        });
    }

    public void OnReportScore()
    {
        Social.ReportScore(10000, leaderboardID, (bool success) => {
            // handle success or failure
            txtReportScoreStatus.text = success.ToString();
        });
    }

    public void OnShowLeaderboard()
    {
        Social.ShowLeaderboardUI();
    }
}

and seeing the logcat, I found some point. that always make this error message like

Key callerUid expected String but value was a java.lang.Integer.  The default value <null> was returned.
Attempt to cast generated internal exception:
 java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at android.os.BaseBundle.getString(BaseBundle.java:1199)
    at hzt.a(:com.google.android.gms@213016046@21.30.16 (150400-391784508):67)
    at hzx.e(:com.google.android.gms@213016046@21.30.16 (150400-391784508):1)
    at hyg.l(:com.google.android.gms@213016046@21.30.16 (150400-391784508):43)
    at kzt.k(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at kzt.eS(:com.google.android.gms@213016046@21.30.16 (150400-391784508):108)
    at edl.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):5)
    at android.os.Binder.transact(Binder.java:1079)
    at eim.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at android.os.Binder.transact(Binder.java:1079)
    at adeg.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):17)
    at android.os.Binder.execTransactInternal(Binder.java:1190)
    at android.os.Binder.execTransact(Binder.java:1159)
 Key suppressProgressScreen expected String but value was a java.lang.Boolean.  The default value <null> was returned.
 Attempt to cast generated internal exception:
 java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at android.os.BaseBundle.getString(BaseBundle.java:1199)
    at hzt.a(:com.google.android.gms@213016046@21.30.16 (150400-391784508):67)
    at hzx.e(:com.google.android.gms@213016046@21.30.16 (150400-391784508):1)
    at hyg.l(:com.google.android.gms@213016046@21.30.16 (150400-391784508):43)
    at kzt.k(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at kzt.eS(:com.google.android.gms@213016046@21.30.16 (150400-391784508):108)
    at edl.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):5)
    at android.os.Binder.transact(Binder.java:1079)
    at eim.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at android.os.Binder.transact(Binder.java:1079)
    at adeg.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):17)
    at android.os.Binder.execTransactInternal(Binder.java:1190)
    at android.os.Binder.execTransact(Binder.java:1159)
 Key keyTokenRequestOptionsAuthExtrasBundle expected String but value was a android.os.Bundle.  The default value <null> was returned.
 Attempt to cast generated internal exception:
 java.lang.ClassCastException: android.os.Bundle cannot be cast to java.lang.String
    at android.os.BaseBundle.getString(BaseBundle.java:1199)
    at hzt.a(:com.google.android.gms@213016046@21.30.16 (150400-391784508):67)
    at hzx.e(:com.google.android.gms@213016046@21.30.16 (150400-391784508):1)
    at hyg.l(:com.google.android.gms@213016046@21.30.16 (150400-391784508):43)
    at kzt.k(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at kzt.eS(:com.google.android.gms@213016046@21.30.16 (150400-391784508):108)
    at edl.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):5)
    at android.os.Binder.transact(Binder.java:1079)
    at eim.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at android.os.Binder.transact(Binder.java:1079)
    at adeg.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):17)
    at android.os.Binder.execTransactInternal(Binder.java:1190)
    at android.os.Binder.execTransact(Binder.java:1159)
 Key gads_service_connection_start_time_millis expected String but value was a java.lang.Long.  The default value <null> was returned.
 Attempt to cast generated internal exception:
 java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
    at android.os.BaseBundle.getString(BaseBundle.java:1199)
    at hzt.a(:com.google.android.gms@213016046@21.30.16 (150400-391784508):67)
    at hzx.e(:com.google.android.gms@213016046@21.30.16 (150400-391784508):1)
    at hyg.l(:com.google.android.gms@213016046@21.30.16 (150400-391784508):43)
    at kzt.k(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at kzt.eS(:com.google.android.gms@213016046@21.30.16 (150400-391784508):108)
    at edl.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):5)
    at android.os.Binder.transact(Binder.java:1079)
    at eim.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):2)
    at android.os.Binder.transact(Binder.java:1079)
    at adeg.onTransact(:com.google.android.gms@213016046@21.30.16 (150400-391784508):17)
    at android.os.Binder.execTransactInternal(Binder.java:1190)
    at android.os.Binder.execTransact(Binder.java:1159)

BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.signin.service.INTERNAL_START id=identifierhack:afd961d8-7fa0-4769-858a-462d62a814d4 pkg=com.google.android.gms (has extras) }
PlayGamesServices[SignInAuthenticator]: **** APP NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES
PlayGamesServices[SignInAuthenticator]: **** DEVELOPER_ERROR
PlayGamesServices[SignInAuthenticator]: **** This is usually caused by one of these reasons:
PlayGamesServices[SignInAuthenticator]: **** (1) Your package name and certificate fingerprint do not match
PlayGamesServices[SignInAuthenticator]: ****     the client ID you registered in Developer Console.
PlayGamesServices[SignInAuthenticator]: **** (2) Your App ID was incorrectly entered.
PlayGamesServices[SignInAuthenticator]: **** (3) Your game settings have not been published and you are 
PlayGamesServices[SignInAuthenticator]: ****     trying to log in with an account that is not listed as
PlayGamesServices[SignInAuthenticator]: ****     a test account.
PlayGamesServices[SignInAuthenticator]: **** (4) A server auth code was requested, but an incorrect client
PlayGamesServices[SignInAuthenticator]: ****     id was provided. The client id for server auth codes should
PlayGamesServices[SignInAuthenticator]: ****     be the client id for the game server (not the android app).
PlayGamesServices[SignInAuthenticator]: ****
PlayGamesServices[SignInAuthenticator]: **** To help you debug, here is the information about this app
PlayGamesServices[SignInAuthenticator]: **** Package name         : {mypackagename}
PlayGamesServices[SignInAuthenticator]: **** Cert SHA1 fingerprint: {myfingerprint}
PlayGamesServices[SignInAuthenticator]: **** App ID from manifest : {my-appid}
PlayGamesServices[SignInAuthenticator]: ****
PlayGamesServices[SignInAuthenticator]: **** Check that the above information matches your setup in 
PlayGamesServices[SignInAuthenticator]: **** Developer Console. Also, check that you're logging in with the
PlayGamesServices[SignInAuthenticator]: **** right account (it should be listed in the Testers section if
PlayGamesServices[SignInAuthenticator]: **** your project is not yet published).
PlayGamesServices[SignInAuthenticator]: ****
PlayGamesServices[SignInAuthenticator]: **** For more information, refer to the troubleshooting guide:
PlayGamesServices[SignInAuthenticator]: ****   http://developers.google.com/games/services/android/troubleshooting
PlayGamesServices[SignInAuthenticator]: ****

here is the full logcat log file when I tried to signin.

I think I've checked the exact tester email address and client ID. and I released internal testing only. is that a problem?

I am using Unity 2020.3.1f1 btw.

Please someone help this issue to be fixed :( 🥲

zhangjianshuai commented 2 years ago

maybe its lack of some library, check yours mainTemplate.gradle? hope helping you~

geoseong commented 2 years ago

@zhangjianshuai

maybe its lack of some library, check yours mainTemplate.gradle? hope helping you~

thank you for replying this, but I don't check Custom Main Gardle Template in Project Settings, should I check this option first?

MarkGree commented 2 years ago

@zhangjianshuai

maybe its lack of some library, check yours mainTemplate.gradle? hope helping you~

thank you for replying this, but I don't check Custom Main Gardle Template in Project Settings, should I check this option first?

check the box "Custom Proguard File" and paste this into the proguard file:

-keep class com.google.android.gms.games.Games. { *; } -keep class com.google.android.gms.games.multiplayer.* { ; } -keep class com.google.android.gms.games.leaderboard. { *; } -keep class com.google.android.gms.games.snapshot. { *; } -keep class com.google.android.gms.games.achievement.* { ; } -keep class com.google.android.gms.games.event. { *; } -keep class com.google.android.gms.games.stats. { *; } -keep class com.google.android.gms.games.video. { ; } -keep class com.google.android.gms.games. { ; } -keep class com.google.android.gms.common.api.ResultCallback { ; } -keep class com.google.android.gms.signin. { *; } -keep class com.google.android.gms.dynamic. { *; } -keep class com.google.android.gms.dynamite. { *; } -keep class com.google.android.gms.tasks.* { ; } -keep class com.google.android.gms.security. { *; } -keep class com.google.android.gms.base. { *; } -keep class com.google.android.gms.actions.* { ; } -keep class com.google.games.bridge. { ; } -keep class com.google.android.gms.common.ConnectionResult { ; } -keep class com.google.android.gms.common.GooglePlayServicesUtil { *; } -keep class com.google.android.gms.common.api. { ; } -keep class com.google.android.gms.common.data.DataBufferUtils { ; } -keep class com.google.android.gms.games.quest. { *; } -keep class com.google.android.gms.nearby.* { ; } -keep class com.unity.androidnotifications.* { ; }

proguard-user.txt will appear after you check the box in the following directory: \Assets\Plugins\Android\ It helped me

geoseong commented 2 years ago

@MarkMa-LS I tried to follow your suggestion and paste that to the Assets/Plugins/Android/proguard-user.txt and I got error when I try to build.

java.io.IOException: proguard.ParseException: Expecting java type before ';' in line 1 of file '{project_path}/Temp/gradleOut/unityLibrary/build/intermediates/consumer_proguard_dir/release/lib1/proguard.txt' See the Console for details.

so I changed some context to put * in { ; } area in Assets/Plugins/Android/proguard-user.txt.

-keep class com.google.android.gms.games.Games.** { *; }
-keep class com.google.android.gms.games.multiplayer.* { *; }
-keep class com.google.android.gms.games.leaderboard.* { *; }
-keep class com.google.android.gms.games.snapshot.* { *; }
-keep class com.google.android.gms.games.achievement.* { *; }
-keep class com.google.android.gms.games.event.* { *; }
-keep class com.google.android.gms.games.stats.* { *; }
-keep class com.google.android.gms.games.video.* { *; }
-keep class com.google.android.gms.games. { *; }
-keep class com.google.android.gms.common.api.ResultCallback { *; }
-keep class com.google.android.gms.signin. { *; }
-keep class com.google.android.gms.dynamic.* { *; }
-keep class com.google.android.gms.dynamite.* { *; }
-keep class com.google.android.gms.tasks.* { *; }
-keep class com.google.android.gms.security.* { *; }
-keep class com.google.android.gms.base.* { *; }
-keep class com.google.android.gms.actions.* { *; }
-keep class com.google.games.bridge.* { *; }
-keep class com.google.android.gms.common.ConnectionResult { *; }
-keep class com.google.android.gms.common.GooglePlayServicesUtil { *; }
-keep class com.google.android.gms.common.api. { *; }
-keep class com.google.android.gms.common.data.DataBufferUtils { *; }
-keep class com.google.android.gms.games.quest. { *; }
-keep class com.google.android.gms.nearby. { *; }
-keep class com.unity.androidnotifications.* { *; }

and apk had generated (build success) but still no luck.

The logs in logcat seems to be changed. this log generated when I click the button and trigger OnSignInToGooglePlayGamesService() event.

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
java.lang.ClassNotFoundException: com.google.android.gms.games.Games
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
    at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:246)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
    ... 8 more
  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <000000000000
geoseong commented 2 years ago

I figured out the right contents of Assets/Plugins/Android/proguard-user.txt and finally it worked!

the only differences between @MarkMa-LS 's suggestion and this repo's proguard are like this below.

anyways thank you for the suggestion, @MarkMa-LS !

-keep class com.google.android.gms.games.Games.** { *; }
-keep class com.google.android.gms.games.multiplayer.** { *; }
-keep class com.unity.androidnotifications.* { *; }

after build success and run in my Android Device and push button to signin, it worked!

logcat's log is like this

Starting Auth with token client.
GooglePlayGames.Android.AndroidClient:Authenticate(Boolean, Action`1)
UnityEngine.Events.UnityAction:Invoke()
UnityEngine.Events.UnityEvent:Invoke()
UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
UnityEngine.EventSystems.StandaloneInputModule:Process()

...

Returning an error code.
GooglePlayGames.Android.<>c__DisplayClass18_0:<Authenticate>b__0(Int32)
System.Action`1:Invoke(T)
System.Action`1:Invoke(T)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
UnityEngine.AndroidJavaProxy:Invoke(String, Object[])
UnityEngine._AndroidJNIHelper:InvokeJavaProxyMethod(AndroidJavaProxy, IntPtr, IntPtr)

Starting Auth with token client.
GooglePlayGames.Android.AndroidClient:Authenticate(Boolean, Action`1)
System.Action`1:Invoke(T)
System.Action:Invoke()
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()

001_SignIn

002_ReportScore

003_Google Play Games