Integrating Firebase Crashlytics for multiple targets in iOS — Part I

Manoj Aher
4 min readJun 16, 2020

--

Firebase Crashlytics is a crash report tool which helps you track the crashes in realtime and highlight the code which led to the crash

We have been using Crashlytics for 5 years now and have benefited by tracking and reporting crashes in the initial development period and in production.

Firebase offers multiple products beside crashlytics, which you explore here. In this tutorial, we will see how you can integrate Crashlytics for multiple environments/targets. We will be using Cocoapods for installing Crashlytics.

Let’s begin by registering the app in Firebase Console.

Step 1: Create a new project from here. Once you are on the console select iOS (highlighted in image) to register an app.

Step 2: Add the Bundle Identifier and Nickname for your app and click on the register app

NOTE: The Bundle Identifier mentioned while registering the app in Firebase and in your XCode app settings should match. You cannot change your bundle id later in crashlytics settings page later on

Step 3: Download the GoogleService-Info.plist. We will add this plist later in the application bundle of your app. You can anytime download the GoogleService-Info.plist from the Firebase Settings page.

Step 4: Create a new XCode project and where we will add Crashlytics SDK and do the initial setup. Navigate the newly created project path in the terminal where we will install crashlytics using cocoapods. We will initialize pod using below command that will create a Podfile for you

pod init

Step 5: Open Podfile in your text editor (I personally use Visual Studio Code for editing Podfile) and add pod ‘Firebase/Crashlytics’. Save and quit your Podfile.

Step 6: Now the terminal run command pod install to install all your pods

Step 7: Open the project workspace with an extension .xcworkspace from the project folder. Expand Pods to ensure all Firebase is added correctly.

Steps 8: Time to initialize Firebase in the app. Open Appdelegate.swift and import Firebase . Open methodapplication:didFinishLaunchingWithOptions and add FirebaseApp.configure() before returning.

Step 9: RememberGoogleService-Info.plist downloaded in Step 3, this needs to be added to the project. Just drag and drop the file in your project exactly as shown in step 3.

In your project select the project file → select the target → select Build Phases tab, then click add New Run Script Phase. Expand the Run Script and then add the below script.

${PODS_ROOT}/FirebaseCrashlytics/run

To get the crashes in debug mode select the target → select Build Settings → selectDebug Information FormatSelect debug flag to DWARF with dSYM File to ensure crashes are reported from the simulator.

Step 11: Let’s go back to Firebase console and complete the app registration that we left on Step 3. We have added the SDK to our app and added the necessary code to initialize the project. Run the app and move till Step 5 of registration.

Select Continue to console to move to the dashboard. You can see and select the Crashlytics from the left pane to view all the crashes. Time to see if the crashes are getting reported in Crashlytics.

Time to Crash the app 💥

Open ViewController.swift and add fatalError() in viewDidLoad method and run the app.

Open the app again on the simulator then go back to Firebase Console to see if the crashes are reported

Hurray! We are done with crashlytics setup for your app. Yes, its that’s easy to add crashlytics to the app. If you still face issues while adding crashlytics let me know down in comments, I will be more than happy to help you.

In the next tutorial, we will be discovering how to handle multiple environments and targets. Till then keep learning 👨‍💻and sharing.

Further Reading:

Part 2 : https://medium.com/@manojaher/integrating-firebase-crashlytics-for-multiple-targets-in-ios-part-ii-b1a7d116ad1c?showDomainSetup=true

--

--