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.

ios

android

unity [beta]

Before you begin

ios

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

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

  • If you don't have an iOS app, you can download a sample app.

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

android

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

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

  • If you don't have an Android app, you can download a sample app.

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

unity [beta]

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

ios

To get started, add the Crashlytics SDK framework files to your project's Xcode workspace. For most projects, the easiest way to do that is by adding the Crashlytics CocoaPods. However, if your project can't support CocoaPods, you can also add the files manually.

android

  1. In your project-level build.gradle, update your google-services to version 3.1.2 or later, then add the Crashlytics repositories and dependency:

    buildscript {
        repositories {
            // ...
    
            // Add repository
            maven {
               url 'https://maven.fabric.io/public'
            }
        }
        dependencies {
            // ...
    
            // Check for v3.1.2 or higher
            classpath 'com.google.gms.google-services:4.2.0'
    
            // Add dependency
            classpath 'io.fabric.tools:gradle:1.26.1'
        }
    }
    
    allprojects { // ... repositories { // ... // Check that you have the following line (if not, add it): google() // Google's Maven repository // ... } }

  2. In your app-level build.gradle, update your firebase-core to version v11.4.2 or later, then add the Crashlytics dependencies:

    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    
    dependencies { // ... // Check for v11.4.2 or higher implementation 'com.google.firebase:firebase-core:16.0.8' // Add dependency implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9' }

After you add the SDK to your app, Crashlytics automatically gets to work listening for and collecting crash reports.

unity [beta]

  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

ios

The frameworks you added include a run script that initializes Crashlytics. Add it to your project's build phases:

  1. Open your project in Xcode, then select its project file in the Navigator.

  2. Select your main build target from the Select a project or target dropdown.

  3. Open the target's Build Phases tab.

  4. Click + Add a new build phase, then select New Run Script Phase.

  5. Add the following line to the Type a script text box:

    CocoaPods install
    "${PODS_ROOT}/Fabric/run"
    Manual install
    "${PROJECT_DIR}/Fabric.framework/run"

  6. Xcode 10 only: Add your app's built Info.plist location to the Build Phase's Input Files field:

    $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)

After you add the SDK to your app, Crashlytics automatically gets to work listening for and collecting crash reports.

android

For Android apps, a hook in the AndroidManifest.xml file automatically initializes the Firebase SDK.

unity [beta]

  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;
    
                      // WARNING: Do not call Crashlytics APIs from asynchronous tasks;
                      // they are not currently supported.
    
                      // 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

ios

Run your app to send verification to Firebase that you've successfully integrated Firebase.

Your device logs will display the Firebase verification that initialization is complete.

android

Run your app to send verification to Firebase that you've successfully integrated Firebase.

Your device logs will display the Firebase verification that initialization is complete. If you ran your app on an emulator that has network access, the Firebase console notifies you that your app connection is complete.

unity [beta]

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

ios

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

You can find more videos on the Firebase YouTube channel.

android

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.

Gửi phản hồi về...

Bạn cần trợ giúp? Truy cập trang hỗ trợ của chúng tôi.