Unity using Google Play Games Services Plugin
This setup is for a absolut basic setup, using the Google Play Games Login only. Assuming you build your app from scratch.
💖 Health Check / Goal Project
Windows 10
Unity 2020.3.14f1 (07, August 2021)
Module: Android Build Support
Module: iOS Build Support (only to avoid a bug using the GPGS Plugin)
2D Template
Play Games Plugin for Unity 0.12.10
2D Mobile Android App
Minimum SDK: Android 30
Set up a Unity Project
Set up Android
Build Settings
Build SettingsCheck
Build App Bundle (Google Play)Click
Switch Platform
Project Settings > Player
Project Settings > PlayerAPI Level 30 is manadatory due to newest google restrictions
Windows To update to API Level 30, ensure to run Unity Hub as administrator.
Other SettingsIdentificationOverride Default Package Name> Check itOverride Default Package Name> Set your<your.package.name>Version> Set your app version0.1.1Bundle Version Code> 1Minimum API Level> Android 11.0 (API Level 30)
ConfigurationScripting Backend> SelectIL2CPPTarget Architectures> CheckARM64
Create your first
<myappbundle>.aabbundleBuild Settings>Build
USB Debugging: Setup
Setup USB Debugging with your OS (e.g. Android)
Install Unity Play Games Services Plugin
Install the latest Play Games Plugin For Unity in your Unity project.
Google Play Console App: Set up app
Create the App
Go to
Google Play Console> Create App > Enter your<appName>Select your default language
Choose app type (probably Game)
Choose
free apporpaid appCheck both Checkboxes
Upload your .aab
Testing>Internal TestingTesters> Add yourgoogle mailas a test accountCreate new releaseApp Integrity>Continue
Testing>Internal TestingApp Bundles
Upload your .aab bundle created by Unity
Testing>Internal TestingSave>Review Release>Start Rollout to Interal TestingTesters>Copy LinkOpen Link (Google Play Store and install the app)
Google Play Services Plugin: Setup
Install the GPGS Plugin for Unity.
Simply download the
.packagefile and double click it while unity project is open
Apply Google Play Services Resource
Go to Google Play Console>Your App>Play Games Services>Configuration>Credentials>Get resources(on the right hand side)Copy its content
Unity>Window>Google Play Games>Setup>Android Setup ...insert copied
resource contentClick
Setup
The resource file should look similar to the following:
<?xml version="1.0" encoding="utf-8"?>
<!--Google Play game services IDs. Save this file as res/values/games-ids.xml in your project.-->
<resources>
<!--app_id-->
<string name="app_id" translatable="false">1234567890123</string>
<!--package_name-->
<string name="package_name" translatable="false">your.package.name</string>
</resources>Implement the code
using UnityEngine;
using System;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
public class PlayGames : MonoBehaviour
{
public int playerScore;
public static PlayGamesPlatform platform;
void Start()
{
if (platform == null)
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
platform = PlayGamesPlatform.Activate();
}
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) =>
{
Debug.LogError($"[CanPromptOnce]: {JsonConvert.SerializeObject(result)}");
});
Social.Active.localUser.Authenticate(success =>
{
if (success)
{
Debug.Log("Logged in successfully");
}
else
{
Debug.Log("Login Failed");
}
});
}
}Allow Unity with Java Access
Allow Unity with Java AccessCurrently there is a bug with building the app. It demands access to JAVA which it should have.
Reload the JDK and SDK in Unity
To fix it, deselect the JDK and the SDK in Unity > Preferences , unselected them and then select them in order again. It will recompile and the build will run in most cases. In my case it didn't, hence I did the second solution.
Last updated
Was this helpful?