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 Apple project. If you don't have an Apple app, 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.

    All Apple platforms supported by Crashlytics (except watchOS) can take advantage of these features from Google Analytics. Note that you need SDK v8.9.0+ for macOS and tvOS apps.

    • 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

Use Swift Package Manager to install and manage Firebase dependencies.

  1. In Xcode, with your app project open, navigate to File > Swift Packages > Add Package Dependency.
  2. When prompted, add the Firebase Apple platforms SDK repository:
  3.   https://github.com/firebase/firebase-ios-sdk
      
  4. Choose the Crashlytics library.
  5. For an optimal experience with Crashlytics, we recommend enabling Google Analytics in your Firebase project and adding the Firebase SDK for Google Analytics to your app. You can select either the library without IDFA collection or with IDFA collection.
  6. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.

Next, configure the Firebase module:

  1. Import the Firebase module in your UIApplicationDelegate:

    Swift

    import Firebase

    Objective-C

    @import Firebase;
  2. Configure a FirebaseApp shared instance, typically in your app's application:didFinishLaunchingWithOptions: method:

    Swift

    // Use the Firebase library to configure APIs.
    FirebaseApp.configure()
    

    Objective-C

    // Use the Firebase library to configure APIs.
    [FIRApp configure];
    

Step 3: Set up Xcode to automatically upload dSYM files

To generate human readable crash reports, Crashlytics needs your project's debug symbol (dSYM) files. The following steps describe how to configure Xcode to automatically produce your dSYMs, process them, and upload the files whenever you build your app.

  1. Open your project's Xcode workspace, then select its project file in the left navigator.

  2. From the TARGETS list, select your main build target.

  3. Click the Build Settings tab, then complete the following steps so that Xcode produces dSYMs for your builds.

    1. Click All, then search for debug information format.

    2. Set Debug Information Format to DWARF with dSYM File for all your build types.

  4. Click the Build Phases tab, then complete the following steps so that Xcode can process your dSYMs and upload the files.

    1. Click > New Run Script Phase.

      Make sure this new Run Script phase is your project's last build phase; otherwise, Crashlytics can't properly process dSYMs.

    2. Expand the new Run Script section.

    3. In the script field (located under the Shell label), add the following run script.

      This script processes your project's dSYM files and uploads the files to Crashlytics.

      "${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
    4. In the Input Files section, add the paths for the following files.

      • Add the path to your project's dSYM files

        This enables Crashlytics to process dSYMs for large apps more quickly.

        ${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}
      • Add the path to your project's built Info.plist file

        This enables Crashlytics to associate an app version with the dSYMs.

        $(SRCROOT)/$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)

For more detailed information about dSYM files and Crashlytics (including how to manually upload dSYM files), visit Get deobfuscated crash reports.

Step 4: 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. Add code to your app that you can use to force a test crash.

    You can use the following code to add a button to your app that, when pressed, causes a crash. The button is labeled "Test Crash".

    Swift

    import UIKit
    
    class ViewController: UIViewController {
      override func viewDidLoad() {
          super.viewDidLoad()
    
          // Do any additional setup after loading the view, typically from a nib.
    
          let button = UIButton(type: .roundedRect)
          button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
          button.setTitle("Test Crash", for: [])
          button.addTarget(self, action: #selector(self.crashButtonTapped(_:)), for: .touchUpInside)
          view.addSubview(button)
      }
    
      @IBAction func crashButtonTapped(_ sender: AnyObject) {
          let numbers = [0]
          let _ = numbers[1]
      }
    }
    

    Objective-C

    #import "ViewController.h"
    
    @implementation ViewController
    ‐ (void)viewDidLoad {
        [super viewDidLoad];
    
        // Do any additional setup after loading the view, typically from a nib.
    
        UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake(20, 50, 100, 30);
        [button setTitle:@"Test Crash" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(crashButtonTapped:)
            forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    
    ‐ (IBAction)crashButtonTapped:(id)sender {
        @[][1];
    }
    
    @end
    
  2. Build and run your app in Xcode. Use the following steps to ensure that your test device or simulator is disconnected from the Xcode debugger (which interferes with Crashlytics).

    1. Click Build and then run the current scheme to build your app on a test device or simulator.

    2. Wait until your app is running, then click Stop running the scheme or action to close the initial instance of your app. This initial instance included the debugger that interferes with Crashlytics.

  3. Force the test crash in order to send your app's first crash report:

    1. Open your app from the home screen of your test device or simulator.

    2. In your app, press the "Test Crash" button that you added using the code above.

    3. After your app crashes, run it again from Xcode so that your app can send the crash report to Firebase.

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