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.

Java 8 support and desugaring for Android builds in Unity 2017 and Unity 2018 (Firebase Unity SDK 8.0.0 and higher)

In May 2021 (Firebase BoM v28.0.0), Firebase disabled desugaring for all its Android libraries (see release note). When building an Android app with Firebase Unity SDK (8.0.0 and higher), you might see the following build error:

> Error while dexing.
 The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle

This change affects Android builds in Unity 2017 and Unity 2018 only. Newer versions of Unity add the compileOptions block by default in gradle build files. To fix this build error in Unity 2017 and Unity 2018, do one of the following:

  • Add a compileOptions block to your gradle template:

    1. Use Gradle as the build system.
    2. Enable Custom Gradle Template under Player Settings.
    3. Add the following lines to mainTemplate.gradle (or module level build.gradle if exporting a project for Android Studio):

      android {
          compileOptions {
              sourceCompatibility 1.8
              targetCompatibility 1.8
          }
      }
      
  • Alternatively, increase the minSdkVersion for your Android project to 26 or above.

See also Android troubleshooting - desugaring build failures.

Issues when building for iOS with Cocoapods

When building for iOS, Cocoapod installation may fail with an error about the language locale, or UTF-8 encoding. There are currently several different ways to work around the issue.

  • From the terminal, run pod install directly, and open the resulting xcworkspace file.

  • Downgrade the version of Cocoapods to 1.10.2. The issue exists only in version 1.11 and newer.

  • In your ~/.bash_profile or equivalent, add export LANG=en_US.UTF-8

How to update the version of Firebase Unity SDKs

The process to update the versions of Firebase Unity SDKs depends on how they were initially imported. Here are the two alternative import methods:

  • Importing .unitypackage files under your project's Assets/ directory
  • Importing using the Unity Package Manager (UPM)
    • This is the recommended way to manage packages in Unity 2018.4+.
    • Use this method to make future version updates easier and your Assets/ directory cleaner.

In your Unity project, you should only use one import method to manage all your Firebase packages. The instructions below can be used to not only update the version of individual packages, but also, if needed, to migrate package management to UPM (the recommended import method).