Community-maintained Google Sign-In plugin for Unity on Android and iOS. The public C# API supports Google account profile data, OAuth ID tokens, server auth codes, additional scopes, and Play Games sign-in.
Version 2.0.0 modernizes the original plugin's build system and platform SDKs while retaining the existing Unity-facing API.
- Unity 2021.3 LTS or newer. Packaging is verified with Unity 2021.3.14f1.
- Android 6.0 (API level 23) or newer.
- iOS 12.0 or newer.
- External Dependency Manager for Unity (EDM4U), included in the plugin package.
The Android library is built with compile/target SDK 35 and uses Google Play services Auth 21.6.0, AndroidX Credentials 1.6.0, and Google ID 1.2.0. The iOS integration uses GoogleSignIn 9.1.0.
Android 2.0.0 uses Credential Manager for the common Google ID token flow when all of the following are true:
RequestIdTokenandRequestEmailare enabled.WebClientIdis set.- Games sign-in, server auth codes, forced refresh, popup suppression, account hints, and additional scopes are not requested.
Requests with advanced options continue through the Google Play services Google Sign-In compatibility flow. A non-cancellation Credential Manager error also falls back to that flow. This keeps existing auth-code, Games, and custom scope configurations working while simple ID-token sign-in uses the modern API.
SignOut() clears local sign-in and credential state. Disconnect() also
attempts to revoke the account authorization granted to the application.
Create OAuth clients for your application in the Google Cloud console or through Firebase:
- Create a Web application client. Its client ID is the
WebClientIdused for ID tokens and server auth codes. - Create an Android client with the Unity package name and the SHA-1 fingerprint of the keystore that signs the application.
- For iOS, create an iOS client for the bundle ID and download
GoogleService-Info.plist.
The Android package name and signing certificate must match the Android OAuth client. Debug and release keystores normally require separate registered SHA-1 fingerprints.
- Import
google-signin-plugin-2.0.0.unitypackage. - Optionally import
GoogleSignIn-sample.unitypackageafter the plugin. The sample package contains only the sample scene and scripts. - Open Assets > External Dependency Manager > Android Resolver > Force Resolve before building Android.
For the sample, open Assets/SignInSample/MainScene, select the Canvas, and set
the Web client ID on the SigninSampleScript component.
- Switch the Unity build target to Android.
- Set Player Settings > Other Settings > Minimum API Level to Android 6.0 (API level 23) or newer.
- Set the package name to the value registered for the Android OAuth client.
- Configure the matching keystore, key alias, and passwords.
- Run EDM4U Force Resolve, then build the application.
To use the Play Games profile, uncomment the play-services-games dependency in
Assets/GoogleSignIn/Editor/GoogleSignInDependencies.xml and resolve Android
dependencies again.
Follow the Google Sign-In for iOS integration guide to configure the iOS OAuth client and URL scheme.
- Set the iOS deployment target to 12.0 or newer.
- Add
GoogleService-Info.plistto the Unity project. - Switch to the iOS build target and run the EDM4U iOS Resolver.
- Export the Xcode project and build the generated
.xcworkspaceso the CocoaPods dependencies are included.
GoogleSignIn.Configuration = new GoogleSignInConfiguration {
WebClientId = "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com",
RequestEmail = true,
RequestIdToken = true
};
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(task => {
if (!task.IsCanceled && !task.IsFaulted) {
GoogleSignInUser user = task.Result;
string idToken = user.IdToken;
}
});For Firebase Authentication, pass the returned ID token to
GoogleAuthProvider.GetCredential(idToken, null), then sign in with the resulting
Firebase credential.
The repository build uses AGP 8.13.2 and Gradle 8.13. Install these prerequisites:
- JDK 17
- Android SDK Platform 35
- Android NDK 29.0.14206865
- CMake 3.22.1 or newer
- Unity, plus Git and network access for fetching EDM4U and Maven dependencies
On Windows PowerShell:
$env:JAVA_HOME = 'C:\Tools\JDK\open-jdk-17.0.2'
$env:ANDROID_HOME = 'C:\Tools\Android\Sdk'
$env:UNITY_EXE = 'C:\Program Files\Unity\2021.3.14f1\Editor\Unity.exe'
.\gradlew.bat -PlintAbortOnError :native-googlesignin:lintRelease build_allOn Linux or macOS, set JAVA_HOME, ANDROID_HOME, and UNITY_EXE, then run:
./gradlew -PlintAbortOnError :native-googlesignin:lintRelease build_allThe build writes these packages to the repository root:
google-signin-plugin-2.0.0.unitypackageGoogleSignIn-sample.unitypackage
The Android native library is linked for 16 KB page-size compatibility on all packaged ABIs.
Copyright 2017 Google Inc. and subsequent contributors. Licensed under the Apache License 2.0.