Before i jump into anything here let me start off by saying that it took me nearly two weeks and 48 uploads to my internal test track to get Google Play Game services working in my Unity game – so yea its a fuckin pain in the ass to say the least to get this shit working. So where the hell do i even start? cause honestly i don’t really know what finally triggered the authentication to return a success message from Google but hey when you throw enough rocks into space one is bound to come back and smack you in the head.

Alright so lets start with the plugin itself – which you can download from the official Github releases page. After you download the source code zip file you’ll want to open the zip file and locate the file labelled “GooglePlayGamesPlugin-2.1.0.unitypackage” from the “current-build” folder. You can then import this package file in Unity under Assets -> Import Package -> Custom Package. After you’ve imported the package you will need to configure the Play Games plugin which you can do under Window -> Google Play Games -> Setup -> Android Setup. In the setup screen (which is a popup window) you will need to provide the “Resources Definition” and a “Web App Client ID” the latter of which is optional. Now in my case i went ahead and added the Client ID because during my phase of trying a million things to see what the fuck works phase i decided add it because it’s possible it could be required to actually authenticate a connection with Google.

Can be found under Window -> Google Play Games -> Setup -> Android Setup

Oh and if you are not sure about the “Resources Definition” you can obtain that from your Google Play Console after you’ve created a leaderboard or achievement – just click on the Get Resources button. See screenshots below so you don’t get fuckin lost somewhere along the way of this treacherous endeavor.

Click on Get resources in play console to obtain your Resources Definition

Now I’m not entirely sure about this next step but i came across a few posts through a Google search where some Unity devs mentioned that adding a value for the “Nearby Connections setup” triggered there authentication to work – this could be a load of shit but during my “getting ready to rip out my hair phase” i decided to go ahead and populate it with my package name – which is the value that’s required for this particular option. Since this is my very first time working with v2.1.0 its possible this option is required so for the sake of sanity feel free to go ahead and add it.

Found under Window -> Google Play Games -> Setup -> Nearby Connections Setup

Ok the next thing you wanna do is get your your Unity code in place so you can communicate with the Google Play Game services. For my project i created a gameObject and assigned it a script called PlayGameServices and made it a singleton so it can persist throughout each of my scenes. Below is an overview of the code i am using to authenticate my connection to Google Play Game services and make additional calls related to leaderboards and achievements:

using System.Collections;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.Events;

public class PlayGamesServices : Singleton<PlayGamesServices> {

    private void Start()
    {
        PlayGamesPlatform.Activate();
        SignIn();
    }
    
    private void SignIn()
    {
        Social.localUser.Authenticate(success =>
        {
            if (success)
            {
                Debug.LogError("Connected to Google pLay services!");
            }
            else
            {
                Debug.LogError("Connection failed");
            }
        });
    }
    
    public void ShowAchievementsUI()
    {
        PlayGamesPlatform.Instance.ShowAchievementsUI();
    }
    
    public void ShowLeaderboards()
    {
        PlayGamesPlatform.Instance.ShowLeaderboardUI();
    }
    
    public void AddScoreToLeaderBoard(int score, string leaderboardId)
    {
        Social.ReportScore(score, leaderboardId, (bool success) => {
            if (success)
            {
                Debug.LogError("Score has been added to leaderboard");
            }
            else
            {
                Debug.LogError("Score was not saved");
            }
    
        });
    
    }

}

Now, if you don’t know what a singleton is then ask ChatGPT to explain it to you : ]

Ok, still with me? if so lets continue, cause this shit is about to get hairy….i kid you not.

So basically everything I’ve outlined so far in this article should be enough to get you connected to the Google Play Game services according to the official docs but nope that’s not the fuckin case at all. So this is where things get hairy because any or all of these next steps may or may not work out for you…its really a case by case scenario and also depends on your version of Unity and the JDK Unity installs with the installation. And then there’s the “Android Resolver” which is found in Unity under “Assets -> External Dependency Manager -> Android Resolver“. Oh and then there’s Android Studio which i believe requires a bunch of SDK’s to be installed so your gradle file gets configured correctly – a gradle file is generated when the “Android Resolver” resolves your files to make your app work with Google services. Oh and i also forgot about the GPGS file in unity which requires a checkbox to be ticked off otherwise the resolver will forget to include the fragmentHelper object which is another requirement for the Google play services plugin to communicate with leaderboards and achievements – after authentication has been validated i should add.

Confused yet? ya i thought so.

Ok so lets start off with the version of Unity and the installed JDK that worked for me – see below:

Unity version 2022.3.62f2
JDK Installed with Unity is based on OpenJDK 11.0.14.1+1

Next, see the screenshot below for my publish settings:

A few key takeaways here is the Custom Proguard File option is checked off and the Release option under Minify is also checked off. According the Github page the Custom Proguard File and Minify Release options should be checked on and there is some code they suggest adding to the custom proguard file to get the authentication process to work. And herein is a nuance that i came across – it turns out if i have the Release option checked on then the minification process excludes a few libraries which is required for GPGS to authenticate so in this scenario i would have to add the code to my custom pro guard file to include the necessary libraries in the build. In my case, i just kept the Release option checked off to avoid having to perform this extra step. Now depending on the size of your game then you may have to minify your project for Google Play store so that’s something to keep in mind. I would recommend reading through the Github page to get a really good understanding of the instructions they provide.

CREDENTIALS!!!

The next thing which is very important is the keystore file – this file is required for app signing and can be generated in Unity using the Keystore Manager option which you can see in the screenshot above. This tool will create a file which contains your “Upload Key” which you will need to assign to your app in Google Play Console AND you will also need to add it to your Google Cloud Console account for upload authentication. After you create your keystore file you will need to include with your build by selecting the “Custom Keystore” checkbox and then selecting the file from the location on your hard drive where the file was saved. You will also need to enter the password which you assigned to your “Alias” during the keystore creation process.

The next think you need to do is obtain the SHA-1 fingerprint from your keystore file by using the following steps and code below which should be executed from your command line in Windows (do not use power shell).

  • Navigate to the following folder:
    • cd\Program Files\Unity\Hub\Editor\2022.3.62f2\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin
  • Type the following and be sure to replace your.keystore with the name of your keystore file:
    • keytool -keystore c:\Games\your.keystore -list -v

Once you do this, and everything worked correctly, you should see all of the information which pertains to your keystore file in the command prompt – see screenshot below for reference:

Once you’ve obtained your SHA-1 key you will need to create a new OAUTH 2.0 Client ID in your Google Cloud Console and assign it the SHA-1 key you just obtained from your keystore file – see screenshot below for reference:

Ok, the next thing we need to do is create an additional OAUTH 2.0 Client ID which contains your “App Signing Key” which is created by Google and can be obtained through your Google Play Console under Test and release -> App Integrity; then scroll down to “Play App Signing” and click on “Settings” – see screenshot below for reference:

On the settings page you can find your SHA-1 App Signing Key under App signing key certificate – see below for reference:

Once you’ve obtained your key proceed with creating the additional OAUTH 2.0 client ID in Google Cloud Console. Once this is done and your app has been uploaded to Google Play (either on internal testing or a closed testing track) you should be able to verify the app ownership in Google Cloud Console – see reference image below:

Ok, so now that we have all this done you’re probably thinking everything should be working fine, right? Well not quite yet. Up to this point, Google Play Game services should be authenticating and logging you into your Google Play upon starting your app however you may notice that your buttons to load your leaderboards and achievements might not be working. Remember that GPGS file i mentioned earlier? Turns out i had to go back into unity, search for a file labelled gpgs-plugin-support-2.1.0 and turn on the Android option from the inspector – see below for reference:

Now its very important that you DO NOT resolve or force resolve before publishing your game otherwise the “Android” option we just checked on will get unchecked by the resolver. So this should essentially be the very last step before publishing your game, or at least in my case it is, in order to get everything working correctly. I should mention that with earlier versions of the Google Play Games plugin i never had to locate this file and check on this option so I’m guessing this is something that is required for version 2.1.0.

Ok so, i actually lied, because after completing all of this shit my authentication still was not working. Remember earlier i mentioned if you throw enough rocks into space one will come back and smack you in the head? The very last final thing i fucking did to try and get this god damn thing to authenticate was i got my OAUTH consent screen approved by Google….HOLY SHIT!!!!

Courtesy of John Candy…R.I.P big guy.

You can get your OAUTH consent screen approved through your Google cloud console under the Branding section – see image below for reference:

SCOPES!!!

I almost forgot to mention that your Google Cloud console project needs to have three scopes assigned to it which can you can reference in the screenshot below:

If these scopes are missing then i can pretty much guarantee your play game services will not authenticate.

Well that’s all…phew!! I make no guarantees that everything i mentioned in this article will work for you but it took me two hours to write this shit out so hopefully it helps someone. I really wish those aholes at Unity would make this process easier but nope, there too busy trying to figure out dumb things like charging a runtime fee on installations…thank God they got rid of that shit those bunch of morons.

If you need any help feel free to reach out to me on my discord channel.