कंसोल पर जाएं

Migrate Unity app from Fabric Crashlytics to Firebase Crashlytics

This quickstart describes how to migrate your existing Fabric Crashlytics Unity app to Firebase Crashlytics so that you can see all of your crash reports in the Firebase console.

Before you begin

The following guide assumes that you have a working Unity app with Fabric. If you do not have an existing Unity app in Fabric, follow the Get Started instructions for users new to Crashlytics.

  1. Sign into Fabric, then navigate to the migration flow.

  2. Check that the Signed into Google as field lists the Google account associated with your Firebase project. If it doesn't, click Switch accounts to select the correct account.

  3. Click Get Started, then click Start Linking.

  4. Drag the appropriate Fabric App on the left into the appropriate Firebase project on the right.

    Note that you can also create a new Firebase project.

  5. Click Link 1 app to Firebase.

Step 2: Remove Fabric

Fabric adds GameObjects to your Scene to initialize Crashlytics in your game as well as additional directories for the SDKs themselves.

To ensure there are no conflicts between the Fabric Crashlytics and Firebase Crashlytics plugins, remove the following Fabric folders and files from your Unity project:

  • Under Assets, delete the following files:

    Assets/
       Editor Default Resources/
           FabricSettings.asset     <- DELETE
       Fabric/                      <- DELETE
       Plugins/
           Android/
               answers/             <- DELETE
               beta/                <- DELETE
               crashlytics/         <- DELETE
               crashlytics-wrapper/ <- DELETE
               fabric/              <- DELETE
               fabric-init/         <- DELETE
           iOS/
               Fabric/              <- DELETE
    
  • In the Hierarchy Window, remove the following GameObjects

    SampleScene
        Main Camera
        Directional Light
        Canvas
        EventSystem
        FabricInit                  <- DELETE
        CrashlyticsInit             <- DELETE
    
  • Remove all Fabric entries in Assets > Plugins > Android > AndroidManifest.xml.

    For example, a known key to remove is: android:name="io.fabric.unity.android.FabricApplication"

    Search and remove other Fabric entries if they exist.

Step 3: Add Firebase config files

  1. Navigate to the Firebase console.

  2. In the top left-hand corner next to Project Overview, click settings, then select Project Settings

  3. For your newly linked apps, download your platform-specific Firebase configuration file(s) for each app that you linked. For a single Unity project, you can have at most two config files.

    • For iOSGoogleService-Info.plist
    • For Androidgoogle-services.json
  4. In your Unity project, open the Project window, then move your config file(s) into the Assets folder.

Step 4: Add the Firebase 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 5: Initialize Firebase 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 6: Replace Fabric API calls

There are a few changes to the API that you will need to account for. For more information, check out the Unity API changes page.

Step 7: Add your Fabric API key

Since your app is already in a linked state with Fabric, you need to provide your app's Fabric API Key to Firebase. This ensures a seamless crash reporting transtion to Firebase Crashlytics and lets you see all historical data in the Firebase Crashlytics dashboard.

  1. In your Unity project, open the Firebase Crashlytics menu by selecting Window > Firebase > Crashlytics.

  2. Enter your Fabric api key under Fabric API Key.

  3. Click Save.

Step 8: Build 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

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

  • Learn about API Changes— See how Crashlytics has evolved from Fabric Crashlytics to Firebase Crashlytics.

  • Add Google Analytics— Combine the power of Google Analytics with Firebase Crashlytics to see the Crash Free Users statistics in the Firebase console.