Catch up on everything we announced at this year's Firebase Summit. Learn more

Get started with Firebase Crashlytics

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

Setting up Crashlytics requires tasks both in the Firebase console and your IDE (like adding a Firebase configuration file and the Crashlytics SDK). To finish setup, you'll need to force a test crash to send your first crash report to Firebase.

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.

  2. Recommended: To get features like crash-free users, breadcrumb logs, and velocity alerts, you need to enable Google Analytics in your Firebase project.

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

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

Step 1: Enable Crashlytics in the Firebase console

  1. Go to the Crashlytics dashboard in the Firebase console.

  2. Make sure your app is selected from the dropdown next to Crashlytics at the top of the page.

  3. Click Enable Crashlytics.

Step 2: Add the Firebase Crashlytics SDK to your app

Note that when you registered your Unity project with your Firebase project, you might have already downloaded the Firebase Unity SDK and added the Crashlytics package.

  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()
        // ...
    }

Step 4: (Android only) Get set up for symbol uploading

The steps in this section are only required for Android apps that use IL2CPP.

  • For Android apps that use Unity’s Mono scripting backend, these steps aren't needed.

  • For Apple platform apps, these steps aren't needed because the Firebase Unity Editor plugin automatically configures your Xcode project to upload symbols.

Crashlytics’s Unity SDK 8.6.1+ automatically includes NDK crash reporting, which allows Crashlytics to automatically report Unity IL2CPP crashes on Android. However, to see symbolicated stack traces for native library crashes in the Crashlytics dashboard, you must upload symbol information at build time using the Firebase CLI.

Complete the following steps to get set up for symbol uploading:

  1. Follow the instructions to install the Firebase CLI.

    If you've already installed the CLI, make sure to update to its latest version.

  2. (only for apps using Android API level 30+) Update your app’s AndroidManifest.xml template to disable Pointer Tagging:

    1. Check the box for Android Player Settings > Publishing Settings > Build > Custom Main Manifest.

    2. Open the manifest template located at Assets/Plugins/Android/AndroidManifest.xml.

    3. Add the following attribute to the application tag: <application android:allowNativeHeapPointerTagging="false" ... />

Step 5: Build your project and upload symbols

iOS+ (Apple platform)

  1. From the Build Settings dialog, export your project to an Xcode workspace.

  2. Build your app.

    For Apple platforms, the Firebase Unity Editor plugin automatically configures your Xcode project to generate and upload a Crashlytics-compatible symbol file to Firebase servers for each build.

Android

  1. From the Build Settings dialog, do one of the following:

    • Export to an Android Studio project to build your project; or

    • Build your APK directly from the Unity Editor.
      Before building, make sure the checkbox for Create symbols.zip is checked in the Build Settings dialog.

  2. Once your build has finished, generate a Crashlytics-compatible symbol file and upload it to Firebase servers by running the following Firebase CLI command:

    firebase crashlytics:symbols:upload --app=FIREBASE_APP_ID PATH/TO/SYMBOLS
    • FIREBASE_APP_ID: Your Firebase Android App ID (not your package name)
      Example Firebase Android App ID: 1:567383003300:android:17104a2ced0c9b9b

    • PATH/TO/SYMBOLS: The path to the symbol file generated by the CLI

      • Exported to an Android Studio project — PATH/TO/SYMBOLS is the unityLibrary/symbols directory, which is created in the exported project root after you build the app via Gradle or Android Studio.

      • Built the APK directly from within Unity — PATH/TO/SYMBOLS is the path of the zipped symbol file generated in the project root directory when your build finished (for example: myproject/myapp-1.0-v100.symbols.zip).

    View advanced options for using the Firebase CLI command for symbol file generation and upload

    Flag Description
    --generator=csym

    Uses the legacy cSYM symbol file generator instead of the default Breakpad generator

    Not recommended for use. We recommend using the default Breakpad symbol file generator.

    --generator=breakpad

    Uses the Breakpad symbol file generator

    Note that the default for symbol file generation is Breakpad. Only use this flag if you've added symbolGenerator { csym() } in your build configuration and you want to override it to use Breakpad instead.

    --dry-run

    Generates the symbol files but does not upload them

    This flag is useful if you want to inspect the content of the files that are sent.

    --debug Provides additional debugging information

Step 6: Force a test crash to finish setup

To finish setting up Crashlytics and see initial data in the Crashlytics dashboard of the Firebase console, you need to force a test crash.

  1. Find an existing GameObject, then add to it the following script. This script will cause a test crash a few seconds after you run your app.

    using System;
    using UnityEngine;
    
    public class CrashlyticsTester : MonoBehaviour {
    
        int updatesBeforeException;
    
        // Use this for initialization
        void Start () {
          updatesBeforeException = 0;
        }
    
        // Update is called once per frame
        void Update()
        {
            // Call the exception-throwing method here so that it's run
            // every frame update
            throwExceptionEvery60Updates();
        }
    
        // A method that tests your Crashlytics implementation by throwing an
        // exception every 60 frame updates. You should see non-fatal errors in the
        // Firebase console a few minutes after running your app with this method.
        void throwExceptionEvery60Updates()
        {
            if (updatesBeforeException > 0)
            {
                updatesBeforeException--;
            }
            else
            {
                // Set the counter to 60 updates
                updatesBeforeException = 60;
    
                // Throw an exception to test your Crashlytics implementation
                throw new System.Exception("test exception please ignore");
            }
        }
    }
    
  2. Build your app and upload symbol information after your build finishes.

    • iOS+: The Firebase Unity Editor plugin automatically configures your Xcode project to upload your symbol file.

    • Android: For your Android apps that use IL2CPP, run the Firebase CLI crashlytics:symbols:upload command to upload your symbol file.

  3. Run your app. Once your app is running, watch the device log and wait for the exception to trigger from the CrashlyticsTester.

    • iOS+: View logs in the bottom pane of Xcode.

    • Android: View logs by running the following command in the terminal: adb logcat.

  4. When you see the exception in your device log, restart your app so that it can send the crash report to Firebase.

  5. Go to the Crashlytics dashboard of the Firebase console to see your test crash.

    If you've refreshed the console and you're still not seeing the test crash after five minutes, enable debug logging to see if your app is sending crash reports.


And that's it! Crashlytics is now monitoring your app for crashes. Visit the Crashlytics dashboard to view and investigate all your reports and statistics.

Next steps