Check out what’s new from Firebase@ Google I/O 2021, and join our alpha program for early access to the new Remote Config personalization feature. Learn more

Troubleshooting & FAQ for Unity and Firebase

This page offers tips and troubleshooting for Unity-specific issues that you might encounter when using Firebase.

Have other challenges or don't see your issue outlined below? Make sure to check out the main Firebase FAQ for more pan-Firebase or product-specific FAQ.

.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:

  1. Remove or disable the following DLLs for all platforms:
    • Parse/Plugins/dotNet45/Unity.Compat.dll
    • Parse/Plugins/dotNet45/Unity.Tasks.dll
  2. Enable the following DLLs for all platforms:
    • Parse/Plugins/Unity.Compat.dll
    • Parse/Plugins/Unity.Tasks.dll

To resolve the compilation error, if you're using .NET 4.x:

  1. Remove or disable the following DLLs for all platforms:
    • Parse/Plugins/Unity.Compat.dll
    • Parse/Plugins/Unity.Tasks.dll
  2. Enable the following DLLs for all platforms:
    • Parse/Plugins/dotNet45/Unity.Compat.dll
    • Parse/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.

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 Template under Player Settings is enabled, modify mainTemplate.gradle.
  • If you use Android Studio to build the exported project, modify module-level build.gradle file.

More details can be found in the multidex user guide.