react-native-firebase V6 Crashlytics

2020-06-10 hit count image

Let's see how to use react-native-firebase(V6) for Firebase Crashlytics.

Outline

In this blog post, I will show how to configure react-native-firebase to use Crashlytics in Firebase.

This blog post is a series. If you want to know more, see the blog posts below.

If you want to know how to use react-native-firebase previous version(V5), see the blog posts below.

Install and prepare react-natiev-firebase

see the blog post to install react-native-firebase, and prepare Firebase project.

Install library

execute the command below to install crashlytics in react-native-firebase.

npm install --save @react-native-firebase/crashlytics

Execute the command below to bind react-native-firebase Crashlytics to iOS project.

cd ios
pod install

Configure Firebase project

Next, we need to configure Google Firebase project for Crashlytics. Go to Firebase Console, and click Crashlytics menu on the left.

crashlytics add sdk

Click Add SDK on the top to add SDK. Also, change iOS/Android by selecting the project beside Crashlytics title, and click Add SDK to add iOS, and Android both.

iOS configuration

Let’s see how to configure react-native-firebase Crashlytics for iOS.

Add Build Phase

We need to configure Build Phase to use Crashlytics on iOS. Double-click ios/[project name].xcworkspace to execute Xcode.

crashlytics build phase

After Xcode is executed, select the project on the left, click Build Phases tab on the right top. To add Build Phase, click + button on the left top, and select New Run Script Phase menu.

crashlytics add script

Open Run Script which added by New Run Script Phase menu, and copy-paste the content below.

"${PODS_ROOT}/Fabric/run"

Execute iOS project

After all settings, execute the command below to start iOS project.

npm run ios

Android Configuration

Let’s see how to configure react-native-firebase Crashlytics on Android.

Fabric setting

We need to configure Fabric to use Crashlytics on Android. open android/build.gradle file and modify it like below.

...
buildscript {
  ...
  repositories {
    ...
    maven {
      url 'https://maven.fabric.io/public'
    }
  }
  dependencies {
    ...
    classpath 'io.fabric.tools:gradle:1.28.1'
  }
  ...
}
...

And then open android/app/build.gradle file and modify it like below.

apply plugin: "com.android.application"
apply plugin: 'io.fabric'
...
applicationVariants.all { variant ->
    ...
}
crashlytics {
    enableNdk true
}

Execute Android project

Execute the command below to start Android project.

npm run android

Completed

Done! We’ve configured react-native-firebase to use Firebase Crashlytics.

crashlytics integration

If you configured react-native-firebase Crashlytics, and start React Native project well, you can see the screen like above.

Posts