Integrate Google Firebase Crashlytics in iOS app using swift

Firebase crashlytics SDK helps developers to get real time crash reports of their apps. Crashlytics SDK logs down a crash and provide information to the developer where exactly its coming from. This way, developer can fix crash occurrence in app next release and make app more stable to its users. In this tutorial, we are going to learn how to integrate Firebase Crashlytics SDK in our iOS app using swift language.

Adding Firebase SDK

First thing we need to add Firebase SDK and other dependencies to our project. Follow the below given steps to add Firebase SDK to the project.

  1. Go to https://console.firebase.google.com/
  2. Click on Add project.
  3. Enter project name.
  4. Link Google analytics to the project.(Follow the steps shown by Firebase console window)
  5. Select current location(country we are residing in).
  6. Accept conditions and click on create project.
  7. Click Continue.
  8. A screen with our project dashboard will open up.
  9. Click on iOS icon as we want to add Firebase SDK for iOS.
  10. Follow the 5 steps, as described in the web page. (Note:- One can chose different installation methods, but the recommended one is via SPM(Swift Package Manager))

Using Firebase Crashlytics SDK

Follow below Steps:

  • Drag and drop GoogleService-Info.plist into the project folder.
  • Open AppDelegate.swift and import Firebase, followe by configure command.
import UIKit
import Firebase

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        return true
    }
}
Add run script for Firebase crashlytics in xcode iOS
  1. Select the project in Project Naviagtor
  2. Select project target listed under TARGETS, in our case its ‘CrashlyticsDemo‘.
  3. Select Build Phases.
  4. Click on + icon, then select New Run Script Phase.
  5. Under shell section add below run script
"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"

Note:- If you are using cocoa pods for installation, then you need to add given below shell command

"${PODS_ROOT}/FirebaseCrashlytics/run"

The above scripts are required as crashlytics requires, app to upload debug symbols. Run script build phase for Xcode will automatically upload debug symbols post-build.
Fore more info check this link: https://firebase.google.com/docs/ios/installation-methods

Next steps is to upload DYSM files. In the Input Files section, add the paths for the locations of the following files:

  1. The location of project’s dSYM files:
${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}

As per documentation, providing the location of your project’s dSYM files enables Crashlytics to process dSYMs for large apps more quickly.

2. The location of your project’s built Info.plist file:

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

As per Firebase crashlytics documentation, providing the location of your project’s built Info.plist file enables Crashlytics to associate an app version with the dSYMs.

Lastly, under Build Settings of TARGETS and PROJECT. Search for Debug information format, and set it as “DWARF with DYSM file”.

Debug information format, and set it as DWARF with DYSM file  xcode ios firebase crashlytics

Where to go from here

In this post, we learned about how can we use Firebase crashlytics in iOS app using swift language. Given advantages provided by crashlytics to report crash inside app in a very descriptive way, it’s a very needy thing to use in the mobile app.