Crashlytics - Android Setup

Additional Android Crashlytics setup: the Gradle plugin dependency and optional NDK crash reporting.

Prerequisites

These steps assume:

  • @react-native-firebase/app and @react-native-firebase/crashlytics are already installed (see Crashlytics usage).
  • You are configuring a React Native CLI Android project. Expo projects should add the @react-native-firebase/crashlytics config plugin, which covers steps 2 and 3 below (see the Expo note below and Expo).
  • You can edit android/build.gradle and android/app/build.gradle, then rebuild Android.
  • Your project meets the minimum versions that the Firebase Android NDK guide lists as prerequisites: Gradle 8.0, Android Gradle plugin 8.1.0 and Google services Gradle plugin 4.4.1.

If you're migrating from Fabric, make sure you remove the fabric.properties file from your Android project. If you do not do this you will not receive crash reports on the Firebase console.

If you're using Expo, make sure to add the @react-native-firebase/crashlytics config plugin to your app.json or app.config.js. The plugin covers only step 2 (the Crashlytics Gradle plugin dependency in android/build.gradle) and step 3 (applying the plugin in android/app/build.gradle). It does not add the Google repository (step 1) or the optional NDK block (step 4), so follow them yourself below; they need a native android/ folder, which npx expo prebuild generates in an Expo project. Because that folder is regenerated by npx expo prebuild --clean and by EAS Build, edits made directly in it may not persist, so a workflow that regenerates it needs those changes made another way (for example a custom config plugin). For instructions on adding the plugin, view the Expo installation section.

Adding Firebase Crashlytics Gradle Tools

These steps are required. If you do not add them, your app will most likely crash at startup with:

"The Crashlytics build ID is missing. This occurs when Crashlytics tooling is absent from your app's build configuration. Please review Crashlytics onboarding instructions and ensure you have a valid Crashlytics account."

1. Add the Google repository (if it's not there already)

Add the Google Maven repository inside the existing buildscript.repositories block of android/build.gradle:

groovy
// File: android/build.gradle. Step 1 of 5 (inside existing buildscript.repositories).
buildscript {
  repositories {
    google()
  }
}

2. Add the Firebase Crashlytics Plugin dependency

Add the Crashlytics Gradle plugin dependency line inside the existing buildscript.dependencies block of android/build.gradle:

groovy
// File: android/build.gradle. Step 2 of 5 (inside existing buildscript.dependencies).
buildscript {
  dependencies {
    classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.8'
  }
}

3. Apply the Firebase Crashlytics Plugin to your app

Apply the com.google.firebase.crashlytics plugin near the top of android/app/build.gradle, after the Android application and Google Services plugins:

groovy
// File: android/app/build.gradle. Step 3 of 5 (top of file, after google-services).
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

4. (Optional) Enable Crashlytics NDK reporting

Crashlytics NDK reporting allows you to capture Native Development Kit crashes, which are crashes in native C and C++ code. The React Native Firebase Android module already includes the Crashlytics NDK library. This step enables the upload of native symbols, which Crashlytics needs to show readable native stack traces. The Firebase Android NDK guide covers the details.

Add a firebaseCrashlytics block inside the existing android.buildTypes.release block of android/app/build.gradle:

groovy
// File: android/app/build.gradle. Step 4 of 5 (optional, inside android.buildTypes.release).
android {
  buildTypes {
    release {
      firebaseCrashlytics {
        nativeSymbolUploadEnabled true
        unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
      }
    }
  }
}

With nativeSymbolUploadEnabled set to true, the Crashlytics Gradle plugin adds an uploadCrashlyticsSymbolFile<BuildVariant> task, for example uploadCrashlyticsSymbolFileRelease. For method names to appear in native stack traces, run that task after each build of your native libraries, for example ./gradlew app:assembleRelease app:uploadCrashlyticsSymbolFileRelease from the android folder.

5. Rebuild the project

Once the above steps have been completed, rebuild your Android project from the project root:

bash
# Project root. Step 5 of 5 (after Gradle plugin configuration).
npx react-native run-android