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.
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"
}
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"
},
}
Login and features implementation
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)
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.
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.