Add Firebase to your Unity project
Power up your Unity games with our Firebase Unity SDKs.
To show how easy it is to plug Firebase into your Unity project, we made a sample game, MechaHamster, that you can download from GitHub, the App Store, and the Google Play Store.
Find out more information about powering up your games with Firebase at our Firebase games page.
Already added Firebase to your Unity project? Make sure that you're using the latest version of the Firebase Unity SDK.
Prerequisites
Install Unity 5.3 or later.
(iOS only) Install the following:
- Xcode 9.4.1 or later
- CocoaPods 1.9.0 or later
Make sure that your Unity project meets these requirements:
- For iOS — targets iOS 10 or later
- For Android — targets API level 16 (Jelly Bean) or later
Set up a physical device or use an emulator to run your app.
For iOS — Set up a physical iOS device or use the iOS simulator.
For Cloud Messaging on iOS, here are the prerequisites:
- Set up a physical iOS device.
- Obtain an Apple Push Notification Authentication Key for your Apple Developer account.
- Enable Push Notifications in XCode under App > Capabilities.
For Android — Emulators must use an emulator image with Google Play.
- Sign into Firebase using your Google account.
If you don't already have a Unity project and just want to try out a Firebase product, you can download one of our quickstart samples.
Step 1: Create a Firebase project
Before you can add Firebase to your Unity project, you need to create a Firebase project to connect to your Unity project. Visit Understand Firebase Projects to learn more about Firebase projects.
Step 2: Register your app with Firebase
You can register one or more apps or games to connect with your Firebase project.
Go to the Firebase console.
In the center of the project overview page, click the Unity icon () to launch the setup workflow.
If you've already added an app to your Firebase project, click Add app to display the platform options.
Select which build target of your Unity project that you’d like to register, or you can even select to register both targets now at the same time.
Enter your Unity project’s platform-specific ID(s).
For iOS — Enter your Unity project’s iOS ID in the iOS bundle ID field.
For Android — Enter your Unity project’s Android ID in the Android package name field.
The terms package name and application ID are often used interchangeably.
Open your Unity project in your Unity IDE, then navigate to the settings section for each platform:
For iOS — Navigate to Build Settings > iOS.
For Android — Navigate to Android > Player Settings > Other Settings.
Your Unity project's ID is the Bundle Identifier value (example ID:
com.yourcompany.yourproject).(Optional) Enter your Unity project’s platform-specific nickname(s).
These nicknames are internal, convenience identifiers and are only visible to you in the Firebase console.Click Register app.
Step 3: Add Firebase configuration files
Obtain your platform-specific Firebase configuration file(s) in the Firebase console setup workflow.
For iOS — Click Download GoogleService-Info.plist.
For Android — Click Download google-services.json.
The Firebase config file contains unique, but non-secret identifiers for your project. To learn more about this config file, visit Understand Firebase Projects.
You can download your Firebase config file again at any time.
Make sure the config file name is not appended with additional characters, like
(2).
Open the Project window of your Unity project, then move your config file(s) into the
Assetsfolder.Back in the Firebase console, in the setup workflow, click Next.
Step 4: Add Firebase Unity SDKs
You can add supported Firebase products to your Unity project using the Unity Package Manager, or you can install the SDKs manually.
Unity Package Manager
If you are using Unity 2018.4 or newer, and .NET 4.x or .NET Standard 2.0, you can install Firebase SDK components using the Unity Package Manager:
Add the Game Package Registry by Google to your Unity project.
If you've never imported the Firebase SDK and EDM4U (formally named Play Services Resolver) before, you can manaully add the following block to
Packages/manifest.json."scopedRegistries": [ { "name": "Game Package Registry by Google", "url": "https://unityregistry-pa.googleapis.com", "scopes": [ "com.google" ] } ]Note that some other SDKs, such as the Facebook SDK, may contain EDM4U in their
.unitypackage. Check ifAssets/ExternalDependencyManagerorAssets/PlayServicesResolverfolders exist. If these folders exist, remove them before installing any Firebase SDK through Unity Package Manager.If you need to migrate an existing SDK or prefer a more interactive method, import the latest External Dependency Manager for Unity (EDM4U).
The Unity Package Manager Resolver will prompt you to add the Game Package Registry by Google to your project. Select the registry and click the Add Selected Registries button.
EDM4U adds the registry to
Packages/manifest.jsonunder your current Unity project folder.You can also manaully add this registry later using the Assets > External Dependency Manager > Unity Package Manager Resolver > Add Registries or Window > Google > Game Package Registry > Add To Project menu options.
Migrate exiting Firebase and EDM4U packages imported through
.unitypackageto Unity Package Manager. This can be done by one of the following methods.After the registry is added by EDM4U, a dialog titled "Migrating Packages" should pop up. This dialog lists every package available to be installed through Unity Package Manager. We recommend you select all of them and click the Apply button.
You can also manually bring up this dialog later using Assets > External Dependency Manager > Unity Package Manager Resolver > Migrate Packages menu options.
You can also manually migrate every packages imported through
.unitypackagewith the following steps.Remove both the Firebase Unity SDK and EDM4U from your
Assetsfolder. EDM4U provides a tool to uninstall managed packages which is accessible using the Assets > External Dependency Manager > Version Handler > Uninstall Managed Packages menu option. Select all Firebase SDKs as well as External Dependency Manager and click Uninstall Selected Packages.- Alternatively you can also remove the SDK manually from Assets folder.
Install Firebase Unity SDK components using the Unity Package Manager by selecting Window > Package Manager and searching for
Firebase. Firebase Unity SDK components can be installed, ugpraded and removed through this interface.
Now you can explore and install any Firebase Unity SDK components or Google packages using the Unity Package Manager by selecting Window > Package Manager. All these components can be installed, ugpraded and removed through this interface.
Manual installation
In the Firebase console, click Download Firebase Unity SDK, then unzip the SDK somewhere convenient.
You can download the Firebase Unity SDK again at any time.
The Firebase Unity SDK is not platform-specific.
In your open Unity project, navigate to Assets > Import Package > Custom Package.
From the unzipped SDK, select the supported Firebase products that you want to use in your app.
Analytics enabled
- Add the Firebase package for Google Analytics:
FirebaseAnalytics.unitypackage - Add the packages for any other Firebase products you want to use in
your app. For example, to use Firebase Authentication and
Firebase Realtime Database:
FirebaseAuth.unitypackageandFirebaseDatabase.unitypackage
Analytics not enabled
Add the packages for the Firebase products you want to use in your app. For example, to use Firebase Authentication and Firebase Realtime Database:
FirebaseAuth.unitypackageandFirebaseDatabase.unitypackage- Add the Firebase package for Google Analytics:
In the Import Unity Package window, click Import.
Back in the Firebase console, in the setup workflow, click Next.
Step 5: Confirm Google Play services version requirements
The Firebase Unity SDK for Android requires Google Play services, which must be up-to-date before the SDK can be used.
Add the following code at the start of your application. You can check for and optionally update Google Play services to the version that is required by the Firebase Unity SDK before calling any other methods in the SDK.
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
You’re all set! Your Unity project is registered and configured to use Firebase.
Known issues
.NET compatibility when using Unity 2017.x and later
Firebase supports .NET 4.x as an experimental build option in Unity 2017 and later. Firebase plugins use components of the Parse SDK to provide some .NET 4.x classes in earlier versions of .NET.
Therefore, the Firebase Unity SDK version 5.4.0 and later provide plugins that
are compatible with either .NET 3.x or .NET 4.x in dotnet3 and dotnet4
directories of the Firebase Unity SDK.
If you import a Firebase plugin that is incompatible with the .NET version enabled in your project, you'll see compile errors from some types in the .NET framework that are implemented by the Parse SDK.
To resolve the compilation error, if you're using .NET 3.x:
- Remove or disable the following DLLs for all platforms:
Parse/Plugins/dotNet45/Unity.Compat.dllParse/Plugins/dotNet45/Unity.Tasks.dll
- Enable the following DLLs for all platforms:
Parse/Plugins/Unity.Compat.dllParse/Plugins/Unity.Tasks.dll
To resolve the compilation error, if you're using .NET 4.x:
- Remove or disable the following DLLs for all platforms:
Parse/Plugins/Unity.Compat.dllParse/Plugins/Unity.Tasks.dll
- Enable the following DLLs for all platforms:
Parse/Plugins/dotNet45/Unity.Compat.dllParse/Plugins/dotNet45/Unity.Tasks.dll
If you import another Firebase plugin:
- In your Unity project, navigate to Assets > Play Services Resolver > Version Handler > Update to enable the correct DLLs for your project.
Unity 2017.1 IL2CPP compilation in .NET 4.x projects
Firebase supports .NET 4.x as an experimental build option in Unity 2017 and later. Firebase plugins use components of the Parse SDK to provide some .NET 4.x classes in earlier versions of .NET.
Therefore, the Firebase Unity SDK version 5.4.0 and later provides type
forwarding DLLs which forward Parse types (for example, Parse implementation of
System.Threading.Tasks.Task) to the .NET framework. Unfortunately, IL2CPP
(a transpiler that converts C# to C++) that is shipped in Unity 2017.1.x does
not correctly process type forwarding DLLs which results in build errors that
resemble the following:
Fatal error in Unity CIL Linker Mono.Cecil.ResolutionException: Failed to
resolve System.Threading.Tasks.TaskCompletionSource`1<T>
There is currently no workaround available for .NET 4.x IL2CPP build errors in Unity 2017.1, so you must upgrade to Unity 2017.2 or later to use .NET 4.x in projects compiled with IL2CPP.
Unity 2017.2 networking
Firebase Realtime Database creates TLS network connections using the .NET networking stack. TLS functionality is broken in Unity 2017.2 when using .NET 4.6 causing the Realtime Database plugin to fail in editors and on desktop.
There is no workaround for this issue, so you must use a different version of Unity, for example version 2017.1 or 2017.3.
Missing Firebase Android config file in Unity 2020.
In order to support versions of Unity that do not have the ability to
customize the Gradle build, the Firebase editor tool generates
Assets/Plugins/Android/Firebase/res/values/google-services.xml as an Android
resource to be packaged into an Android build, so that the Firebase SDK can use
it to initialize the default FirebaseApp instance.
In Unity 2020, all Android resources must be in directories with a
.androidlib suffix. If your project is using a Firebase SDK that generates an
Assets/Plugins/Android/Firebase directory, rename it to
Assets/Plugins/Android/Firebase.androidlib. Make sure it contains
AndroidManifest.xml, project.properties and
res/values/google-services.xml.
Installation Conflict when using Unity Package Manager
A package can be installed from different sources. For example, External Dependency Manager for Unity (EDM4U in short, previously called Play Services Resolver or Unity Jar Resolver) can be installed by any of the following ways.
- Importing the External Dependency Manager
.unitypackage. - Importing the Firebase SDK or other SDK which contains EDM4U in their
.unitypackage. - Installing External Dependency Manager through Unity Package Manager
- Installing the Firebase SDK or other SDK which sets EDM4U as its dependency through Unity Package Manager.
When EDM4U is installed through .unitypackage and through
Unity Package Manager at the same time, there is an installation conflict, and
Unity may show an error about a GUID conflict or symbol conflict. EDM4U
currently does not offer resolution for such situations. When this happens,
here is workaround:
- If you have migrated Firebase and EDM4U to Unity Package Manager before
and you import another SDK containing EDM4U in
.unitypackage, for example, Google Ads or Facebook SDK, you can simply remove theAssets/ExternalDependencyManagerand/orAssets/PlayServicesResolverfolders. - If you accidentally installed EDM4U through Unity Package Manager before
removing it from
Assetsfolder first, use the following steps to resolve the conflict:- Remove the
Assets/ExternalDependencyManagerand/orAssets/PlayServicesResolverfolders. - Uninstall all Firebase and EDM4U packages from Unity Package Manager
- Reinstall all needed Firebase and EDM4U packages from UPM.
- Remove the
Issues with Firebase installed through Unity Package Manager in Unity 2018
When Firebase is installed through Unity Package Manager in Unity 2018,
EDM4U may not be able to discover some of Firebase's Android and iOS
native dependencies. This is because files in packages installed as a dependency
are not registered to Unity's AssetDatabase. The most common issue is being
unable to create a FirebaseApp in Android due to a DllNotFoundException.
For example, when Realtime Database is installed through
Unity Package Manager, both Auth and Firebase App (Core) are automatically
installed as its dependencies. However, EDM4U is not able to discover
AuthDependencies.xml and AppDependencies.xml, which contain their
Android and iOS native dependencies, because they are not registered in
AssetDatabase in Unity 2018. As a result, some native libraries may be missing
in the Android or iOS build.
The workaround for this issue is to make sure all Firebase packages are
explicitly installed through Unity Package Manager. For example, if you would
like to install Realtime Database, make sure to click install for Auth and
Firebase App (Core) through Unity Package Manager as well.
An issue with single dex while building Android app
While building Android app, you may encounter a build failure related to having a single dex file. The error message looks similar to the following, if your project is configured to use the Gradle build system.
Cannot fit requested classes in a single dex file.
Dalvik Executable (.dex) files are used to hold a set of class definitions
and their associated adjunct data for Android applications (.apk). A single dex
file is limited to reference to 65,536 methods. The build will fail if the total
number of methods from all Android libraries in your project exceeds this limit.
Unity introduced Minification in 2017.2, which uses Proguard (or other tools in some versions of Unity) to strip out unused code, which can reduce the total number of referenced methods in a single dex file. The option can be found in Player Settings > Android > Publishing Settings > Minify. The options may differ in different version of Unity so refer to the official Unity documentation.
If the number of referenced methods still exceeds the limit, another option is
to enable multidex. There are multiple ways to achieve this in Unity:
- If
Custom Gradle TemplateunderPlayer Settingsis enabled, modifymainTemplate.gradle. - If you use Android Studio to build the exported project, modify
module-level
build.gradlefile.
More details can be found in the multidex user guide.
Set up a desktop workflow (beta)
When you're creating a game, it's often much easier to test your game in the Unity editor and on desktop platforms first, then deploy and test on mobile devices later in development. To support this workflow, we provide a subset of the Firebase Unity SDKs which can run on Windows, macOS, Linux, and from within the Unity editor.
Set up a desktop-platform Unity project by following the same instructions as for a mobile platform (start with the Register your app with Firebase step above.
Run your Unity project in the Unity IDE or select to build your Unity project for desktop.
(Optional) Run your Unity project in Edit Mode.
The Firebase Unity SDK can also be run in Unity's edit mode, allowing its use in editor plugins.
When you create a
FirebaseAppused by the editor, don't use the default instance.Instead, provide a unique name to the
FirebaseApp.Create()call.This is important to avoid a conflict in options between the instance used by the Unity IDE and the instance used by your Unity project.
Supported Firebase products
Learn more about the Unity Firebase libraries in the reference documentation.
The Firebase Unity SDK supports the following Firebase products on iOS and Android:
| Firebase product | Unity package |
|---|---|
| AdMob | Distributed separately in the AdMob Unity Plugin |
| Analytics | FirebaseAnalytics.unitypackage |
| Authentication | FirebaseAuth.unitypackage |
| Cloud Firestore (alpha) | FirebaseFirestore.unitypackage |
| Cloud Functions | FirebaseFunctions.unitypackage |
| Cloud Messaging | FirebaseMessaging.unitypackage(recommended) FirebaseAnalytics.unitypackage |
| Cloud Storage | FirebaseStorage.unitypackage |
| Crashlytics | FirebaseCrashlytics.unitypackage(recommended) FirebaseAnalytics.unitypackage |
| Dynamic Links | FirebaseDynamicLinks.unitypackage(recommended) FirebaseAnalytics.unitypackage |
| Realtime Database | FirebaseDatabase.unitypackage |
| Remote Config | FirebaseRemoteConfig.unitypackage(recommended) FirebaseAnalytics.unitypackage |
Supported Firebase products (desktop)
The Firebase Unity SDK includes desktop workflow support for a subset of products, enabling certain parts of Firebase to be used in the Unity editor and in standalone desktop builds on Windows, macOS, and Linux.
| Firebase product (desktop) | Unity package |
|---|---|
| Authentication | FirebaseAuth.unitypackage |
| Cloud Functions | FirebaseFunctions.unitypackage |
| Cloud Firestore (alpha) | FirebaseFirestore.unitypackage |
| Cloud Storage | FirebaseStorage.unitypackage |
| Realtime Database | FirebaseDatabase.unitypackage |
| Remote Config | FirebaseRemoteConfig.unitypackage |
Firebase provides the remaining desktop libraries as stub (non-functional) implementations for convenience when building for Windows, macOS, and Linux. Therefore, you don't need to conditionally compile code to target the desktop.
Next steps
Explore sample Firebase apps.
Prepare to launch your app:
- Set up budget alerts for your project in the GCP console.
- Monitor your Usage and billing dashboard in the Firebase console.
- Review the Firebase launch checklist.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
