This guide contains instructions for the latest version of the Firebase Crashlytics SDK. If you migrated your app from Fabric, make sure it's been upgraded and no longer uses the deprecated legacy Fabric SDK.

Get started with Firebase Crashlytics

This quickstart describes how to set up Firebase Crashlytics in your app with the Firebase Crashlytics SDK, so you can get comprehensive crash reports in the Firebase console.

Before you begin

  1. If you haven't already, add Firebase to your Unity project. If you don't have a Unity project, you can download a sample app.

    Note that adding Firebase to your Unity project involves tasks both in the Firebase console and in your open Unity project (for example, you download Firebase config files from the console, then move them into your Unity project).

  2. Optional: To get crash metrics such as crash-free users, breadcrumbs, and custom events, you'll need to enable Google Analytics in your Firebase project.

    1. If your existing Firebase project doesn't have Google Analytics enabled, you can enable Google Analytics from the Integrations tab of your > Project settings.

      If you're creating a new Firebase project, enable Google Analytics during the project creation workflow.

    2. Finally, in the Google Analytics console, enable data sharing in the Admin tab > Account Settings > Data Sharing Settings.

      For older Firebase projects, note that you may need to enable data sharing in the Integrations tab of your > Project settings (in the Firebase console).

Step 1: Set up Crashlytics in the Firebase console

  1. Click Crashlytics in the left-hand nav panel of the Firebase console.

  2. If your Firebase project has multiple apps registered in it, select the app you just added from the dropdown next to Crashlytics in the top bar of the console.

  3. Click Enable Crashlytics.

Step 2: Add Firebase Crashlytics to your app

  1. Download the Firebase Unity SDK, then unzip the SDK somewhere convenient.

    The Firebase Unity SDK is not platform-specific.

  2. In your open Unity project, navigate to Assets > Import Package > Custom Package.

  3. From the unzipped SDK, select to import the Crashlytics SDK (FirebaseCrashlytics.unitypackage).

    You can import any other supported Firebase product, as well.

  4. In the Import Unity Package window, click Import.

Step 3: Initialize Crashlytics

  1. Create a new C# script, then add it to a GameObject in the scene.

    1. Open your first scene, then create an empty GameObject named CrashlyticsInitializer.

    2. Click Add Component in the Inspector for the new object.

    3. Select your CrashlyticsInit script to add it to the CrashlyticsInitializer object.

  2. Initialize Crashlytics in the script's Start method:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    // Import Firebase
    using Firebase;
    
    public class CrashlyticsInit : MonoBehaviour {
        // Use this for initialization
        void Start () {
            // Initialize Firebase
            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.
                    // Crashlytics will use the DefaultInstance, as well;
                    // this ensures that Crashlytics is initialized.
                    Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;
    
                    // Set a flag here for indicating that your project is ready to use Firebase.
                }
                else
                {
                    UnityEngine.Debug.LogError(System.String.Format(
                      "Could not resolve all Firebase dependencies: {0}",dependencyStatus));
                    // Firebase Unity SDK is not safe to use here.
                }
            });
        }
    
      // Update is called once per frame
      void Update()
        // ...
    }

With the SDK added and initialized, Crashlytics automatically gets to work listening for and collecting crash reports.

Step 4: Run your project

After exporting your project to iOS or to Android, verify that the project exported correctly.

If it seems like files are missing after comparing your project to the sample export configurations below, open your Unity Editor, then run the Google Play Services Resolver.

iOS

Android

Run the resolver (optional)

The Google Play Services Resolvers make sure that your Unity project has the appropriate dependencies for exporting your app to iOS or to Android.

For more information on the resolver, visit the README for the Unity Jar Resolver.

iOS

The iOS Resolver runs automatically and leverages Cocoapods to put iOS dependencies in the exported Pods directory.

  • To download Cocoapods to your machine:

    • Navigate to Assets > Play Services Resolver > iOS Resolver > Install Cocoapods
  • To enable or disable generation of podfiles (optional):

    • Navigate to Assets > Play Services Resolver > iOS Resolver > Settings

Android

The Android Resolver runs automatically and leverages gradle to put Android dependencies in Assets/Plugins/Android.

  • To manually run the resolver:

    • Navigate to Assets > Play Services Resolver > Android Resolver > Resolve
  • To enable or disable auto-resolution (enabled by default):

    • Navigate to Assets > Play Services Resolver > Android Resolver > Settings

Next steps