Skip to content Skip to sidebar Skip to footer

Google Play Sign In For Unity

I am trying to integrate Google play Services so that i can have achievements and leader boards in my game.I have tried the following code - public Text myText; void Awake() {

Solution 1:

You can test GPS on your unity game locally!!!

I see your comment on the question as RESOLVED saying apk has to be uploaded and published to get this working. In a way that is correct. But, that will be the painful thing to do if you want to upload apk everytime when you want to test your GPS code.

Here is the thing that worked for me for testing it locally without uploading to Google Play Console.

GPS plugin version 0.9.50

  • Make sure to follow the instructions on github of GPS plugin
  • Set the JAVA path correctly on system before installing the plugin
  • Make sure you followed the app signing process with Unity (Keystore, Key)
  • Setup your Google play console for your game and linked app, etc
  • Upload your apk for internal testing or alpha/beta testing

Now, under your Application --> Release Management --> App Signing, Google would have replaced your upload certificate (the Key you setup with Unity) with its own App signing certificate. That's where we get the issue while running the apk directly on device.

While hitting "Build & Run" on unity with Keystore and Key options enabled on Publish settings, your apk will be built and copied to your phone directly by unity. Now while running your game, GPS plugin will try to access Google Play Service, but will fail due to SHA1 mismatch. Your local apk has SHA1 of Upload certificate and GPS is expecting the updated SHA1 certificate (Google's one).

For testing purpose, copy the SHA-1 certificate fingerprint of Upload Certificate from Google Play Console to your Google Developer Console (find your application and click on edit button on right)

Google Play ConsoleGoogle Play Console

Google Developer Consoleenter image description here

On unity build settings, make sure Keystore and Key are selected with correct passwords and hit "Build and Run". Note that, if you already have play store version or unsinged version installed on your phone, uninstall it first.

enter image description here

Now, everytime you update your code, you don't need to upload and publish on Google Play Console to test the GPS plugin. With your local upload certificate, you can test it directly on your phone as good as your normal testing.

Important: After testing, you need to revert the SHA1 back to Google's one to get your GPS working on released versions (Playstore versions). Until you keep the upload key SHA1 under Google Developer Console, Playstore versions of your game will fail to access GPS.

Code for GPS service (I have cloud service enabled as well),

voidInitGooglePlatform()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.Activate();
    if(!bGoogleCheck)       // internal flag to do this only once if user is offline
        GoogleSignin();
    bGoogleCheck = true;    // Mark it done until the game is restarted again
}
publicvoidGoogleSignin()
{
    if (!Social.localUser.authenticated)
    {
        Social.localUser.Authenticate(success => {
            if(success)
            {
                OpenSave(false);
            }
        });
    }
}

Solution 2:

Maybe you have missed the configuration steps? This code is from the link, and anyway it assumes you have also configured the settings.

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

PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    // enables saving game progress.
    .EnableSavedGames()
    // registers a callback to handle game invitations received while the game is not running.
    .WithInvitationDelegate(<callback method>)
    // registers a callback for turn based match notifications received while the// game is not running.
    .WithMatchDelegate(<callback method>)
    // requests the email address of the player be available.// Will bring up a prompt for consent.
    .RequestEmail()
    // requests a server auth code be generated so it can be passed to an//  associated back end server application and exchanged for an OAuth token.
    .RequestServerAuthCode(false)
    // requests an ID token be generated.  This OAuth token can be used to//  identify the player to other services such as Firebase.
    .RequestIdToken()
    .Build();

PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();

Solution 3:

Thanks a lot, you litterally saved me weeks since I had to upload my aab to google play console and wait for google validation.

By the way, there's an issue which cost me many many time and for which I didn't saw any explanation on internet.

Sometimes you can have the following message : WARNING: playgamesplatform already initialized. ignoring this call.

This will prevent you to use the save feature of the platform. In fact this is due to the fact that you may be calling playgamesplatform.instance before calling PlayGamesPlatform.InitializeInstance(config);

for example, performing a :

if (PlayGamesPlatform.Instance.localUser.authenticated == true)
{
...
}

Will force the platform to instanciate. Thus when you really try to instanciate it, it tells you it's already done

Solution 4:

i had the same problem too :), try to use the latest version of GPGs 9.42 for the moment ( 19/11/2017 ), try to cancel the other plugins like Admob , Facebook or onesignal and reintegrate it again, the problem is coming from your plugins not from your code :).

make sure that u added your tests Emails in Console Google Play, and create 3 Linked applications, 2 android applications with your SHA1 (signed and upload) and 1 Web linked app ( put your Google play link into the link space ) and everything should work :).

Good Luck

Post a Comment for "Google Play Sign In For Unity"