🏆 [TUTORIAL] How to integrate the gpgs.v3 plugin (Google Play Games) with achievements and leaderboards in Solar2D

:speech_balloon: Introduction

After four days of dedication and some headaches, I finally managed to integrate the gpgs.v3 plugin into my Solar2D project, implementing achievements and leaderboards without using Snapshots. I want to thank @famousdoggstudios for the forum post that helped me identify one of my mistakes:

Among the tips shared, this one revealed one of the problems that caused it not to work:
The SHA-1 fingerprint used in the Google Cloud Console configuration must be the same as the one used by Google to sign the app, and not the local keystore used during the build. This is a common mistake, so check carefully.
In my case, I was using the wrong SHA-1.

Additionally, I’d like to clarify that linking Firebase is not required to use achievements (gpgs.achievements) and leaderboards (gpgs.leaderboards.submit).
In this tutorial, I share the step-by-step process that worked for me, hoping to save you from the same frustration. :sweat_smile:

:electric_plug: Plugin used

I added the gpgs.v3 plugin in the build.settings file with the following configuration:

["plugin.gpgs.v3"] = {
    publisherId = "com.solar2d",
    version = "v5"
}

:hammer_and_wrench: Basic configuration in build.settings

Set the googlePlayGamesAppId and include the necessary permissions.
Note: The GET_ACCOUNTS permission is obsolete and should not be used.
Here is the complete example I used:

android = {
    googlePlayGamesAppId = "YOUR_NUMERIC_ID_HERE",
    usesPermissions = {
        "android.permission.INTERNET",
        "android.permission.ACCESS_NETWORK_STATE"
    },
}

:calling: Login and features implementation

:exclamation: Important: It is not necessary to use gpgs.isAuthenticated() if you are not using Snapshots.
The code below shows how to initialize the plugin, log in the player, unlock achievements, and send scores to the leaderboard.

-- Function to send score to leaderboard
local function sendScore(score)
    gpgs.leaderboards.submit({
        leaderboardId = "YOUR_LEADERBOARD_ID", -- Enter your leaderboard ID
        score = score,
        listener = function(event)
            if event.isError then
                showMessage("Error submitting score: " .. event.errorMessage)
            else
                showMessage("Score submitted successfully!")
            end
        end
    })
end

-- GPGS plugin initialization
gpgs.init(function(event)
    if not event.isError then
        -- Check if the user is connected
        if gpgs.isConnected() then
            -- Unlock an achievement
            gpgs.achievements.unlock({
                achievementId = "YOUR_ACHIEVEMENT_ID", -- Enter your achievement ID
                listener = function(event)
                    if event.isError then
                        showMessage("Error unlocking achievement: " .. event.errorMessage)
                    else
                        showMessage("Achievement unlocked successfully!")
                    end
                end
            })

            -- Submit a sample score
            sendScore(1992)

        else
            showMessage("User is not connected. Starting login...")
            -- Try to log in
            gpgs.login({
                userInitiated = false,
                listener = function(event)
                    if not event.isError then
                        showMessage("Login successful!")
                    else
                        showMessage("Login error: " .. (event.errorMessage or "Unknown"))
                    end
                end
            })
        end
    else
        showMessage("GPGS initialization error: " .. (event.errorMessage or "Unknown"))
    end
end)

:pushpin: Final tips

  • Check the SHA-1: Make sure you’re using the correct SHA-1 from the Google Play Console, not from your local keystore.
  • To make it work, you must configure the Google Play Console:

– 1 - Upload your game to an internal testing track (it must not be paused) so it can be signed by Google. Save and publish – it won’t be visible to everyone.

– 2 - Add your email as a tester in the internal test track.

– 3 - Go to “Google Play Games Services” > “Setup and Management” > “Testers”. Add the internal test track in “Release Tracks”! Your email should appear under the “Testers” tab.

– 4 - Test on a real device: Google Play Games features won’t work on an emulator.

– 5 - Google Play Console: Properly set up the achievement and leaderboard IDs before testing.

:books: Official documentation: Refer to the gpgs.v3 plugin documentation for more details.
I hope this tutorial is helpful and makes it easier for you to integrate Google Play Games with Solar2D. :rocket:

9 Likes

Glad you eventually got it working and thanks on behalf of the community for compiling your findings and posting them here-- I’m sure this would help someone!

It’s interesting that you were able to get the leaderboards working without connecting your project to Firebase. Did you not have to use the play services json file in your project or is there another place where this file can be downloaded from? I always thought it was a requirement to have that file linked in the Android project and that it had to be downloaded from firebase.

1 Like

Hi @famousdoggstudios, I didn’t need the “Play Services json file”, and there is no download for this file.

1 Like

Nice tutorial, thank you!

1 Like

Thank you so much for your contribution.
It’s been a while since I last set up Google Play Games in any of my games.

One thing I recall giving me a bit of trouble when configuring Google Play Games was something related to OAuth in Google Cloud. Didn’t you have to do anything OAuth-related?

1 Like

Yes, @aclementerodrguez.
It was necessary to access the “OAuth consent screen” → “Clients” page and register a new client. At this stage, it’s important to correctly enter the package name of your game and the SHA-1, which must match the one used in the Google Play Console.

It’s also necessary to configure data access by adding the following non-sensitive scopes:

  • ../auth/drive.appdata
  • ../auth/games

Additionally, make sure to properly configure the branding and target audience, which must be set to production, not testing.

And by the way…
If you can, try out my game! :smile:
Any feedback is very welcome!

download : https://play.google.com/store/apps/details?id=com.solar2d.carlos.BallSortChallenge

1 Like

Thank you @cmaiia … I will download it and let you know my feedback :+1:

1 Like