Firebase Crash Reporting creates detailed reports of the errors in your app. Errors are grouped into clusters of similar stack traces, and triaged by the severity of impact on your users. In addition to automatic reports, you can log custom events to help capture the steps leading up to a crash.
Set up Crash Reporting
To set up Crash Reporting in your app:
- Install the Firebase SDK.
- In the Firebase console, add your app to your Firebase project.
- Add the dependency for Firebase Crash Reporting to your Podfile:
pod 'Firebase/Crash'
- Import the Firebase module:
Objective-C
@import Firebase;
Swift
import Firebase
- Configure a
FIRApp
shared instance, typically in your application'sapplication:didFinishLaunchingWithOptions:
method:Objective-C
// Use Firebase library to configure APIs [FIRApp configure];
Swift
// Use Firebase library to configure APIs FIRApp.configure()
Upload symbol files
In order to view human friendly crash reports, you need to upload symbol files after each build. This can be done automatically by adding a run script to Xcode.
- Download a service account key to authenticate your uploads:
- Go to the Firebase console and open your Firebase project.
- Click and select Permissions.
- On the Permissions page, select Service Accounts from the left menu.
- Click Create service account.
- Name the service account "Symbol Upload service account".
- Set the Role to Editor (Project -> Editor)
- Check the box for Furnish a new private key.
- Select the JSON option for key type.
- Click Create. This automatically downloads a JSON file with the required keys.
- Add an upload script for your symbol files:
- In Xcode, click on your application target, select Build Phases, and click `+` to add a phase.
- Select Run Script and add the following content, setting
appropriate values for your service account path and GOOGLE_APP_ID:
# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file GOOGLE_APP_ID=1:my:app:id # Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded "${PODS_ROOT}"/FirebaseCrash/upload-sym "/Path/To/ServiceAccount.json"
Create your first error
- Add an assert to your AppDelegate's
didFinishLaunchingWithOptions
method to cause a crash when the app launches, right after the Firebase initialization call:
Objective-C
assert(false);
Swift
fatalError()
- Launch the app from Xcode.
- Click Stop in Xcode to detach from the debugger.
- Launch the app directly from the home screen on the device or emulator.
- Wait until your app crashes.
- Remove the crashing line so your app can start successfully.
- Launch the quickstart from Xcode again. Within 15 secs you should see a log message indicating that the report was successfully uploaded.
- Check the Crash Reporting section of the Firebase console to see the error. Note that it takes 1-2 minutes for errors to show there.
Create custom logs
You can use FIRCrashLog()
to create custom log messages that are included in your
crash reports. The following example demonstrates creating a log message:
Objective-C
FIRCrashLog(@"Cause Crash button clicked"); assert(NO);
Swift
FIRCrashMessage("Cause Crash button clicked") fatalError()
Known issues
Device models may not be showing in error reports. This will be addressed in an upcoming Pod update.