Перейти к консоли

Get started with Firebase Crashlytics

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

Before you begin

Before you can set up Crashlytics, you need to register your Unity project and configure it to use Firebase.

  • If your Unity project already uses Firebase, then it's already registered and configured for Firebase.

  • 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).

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 Set up Crashlytics.

  4. Select This app is new to Crashlytics (it doesn't have any version of the SDK).

Step 2: Add the Crashlytics SDK

  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: Build or 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

Watch a video tutorial

For detailed guidance on getting started with Crashlytics, watch the following video tutorial:

You can find more videos on the Firebase YouTube channel.

Next steps

  • Test your implementation— Test your Crashlytics setup by forcing a crash to generate a crash report in the Firebase console.

  • Customize crash reports— Crashlytics automatically starts collecting crash reports as soon as you add the SDK, but you can also customize your setup by adding opt-in reporting, logs, keys, and even tracking of non-fatal errors.