Navigate back to the homepage

Implement react native firebase crashlytics on android

Infinitbility
Firebase, React Native
December 12th, 2020 · 1 min read

Hello Friends,

Welcome To Infinitbility!

This tutorial is part of React Native Firebase crashlytics Series.

React Native Firebase crashlytics In android
React Native Firebase crashlytics In iOS

Today, we implement react native firebase crashlytics on android.

Many Folks, stuck on firebase crashlytics setup then please read and follow all steps carefully…

What is Firebase Crashlytics

Firebase Crashlytics helps you track, prioritize, and fix stability issues that erode app quality, in realtime. Spend less time triaging and troubleshooting crashes and more time building app features that delight users.

— Firebase Crashlytics


Setup Firebase Project

Go To Firebase console and create a new project

https://console.firebase.google.com/

follow the image when you want to see the steps of creating a Firebase project.

Create A Project
  • Click on Create A Project button to firebase journey
Write your project name
  • Write your project name, accept term & condtion and click on continue
Click on continue button
  • Click on continue button
choose your google account
  • choose your google account & Click on continue button
firebase project ready to use
  • firebase project ready to use

Configure Android with Firebase

Below steps explain, connect your firebase account to react native application.

  1. Click on android icon on firebase dashboard for setup application

    click on android icon
  2. Write your app name like on below image with nick native and click on next button

    click on android icon
  3. Download google-services.json file and put on your — projectname/android/app — folder.

    click on android icon
  4. Open your android level build.gradle file and add below code

    path - projectname/android/build.gradle

    1// projectname/android/build.gradle
    2
    3buildscript {
    4 ...
    5 repositories {
    6 google() // add a line when not available
    7 ...
    8 }
    9 dependencies {
    10 ...
    11 classpath 'com.google.gms:google-services:4.3.4' // add line
    12 ...
    13 }
    14}
    15
    16allprojects {
    17 repositories {
    18 ...
    19 google() // add a line when not available
    20 ...
    21 }
    22}
  5. Open your app level build.gradle file and add below code

    path - projectname/android/app/build.gradle

    1// projectname/android/app/build.gradle
    2
    3apply plugin: "com.android.application"
    4apply plugin: 'com.google.gms.google-services' // add on second line below com.android.application
    5
    6...
    7
    8dependencies {
    9 ...
    10 implementation platform('com.google.firebase:firebase-bom:26.1.1') // add line
    11 implementation 'com.google.firebase:firebase-analytics' // add line
    12 ...
    13}
    14
    15...

Configure Android with Firebase Crashlytics

  1. install react native firebase app and crashlytics module using below command

    — for yarn users

    1# Install & setup the app module
    2yarn add @react-native-firebase/app
    3
    4# Install the Crashlytics module
    5yarn add @react-native-firebase/crashlytics

    — for npm users

    1# Install & setup the app module
    2npm install @react-native-firebase/app
    3
    4# Install the Crashlytics module
    5npm install @react-native-firebase/crashlytics
  1. link your firebase packages

    1# link @react-native-firebase/app
    2npx react-native link @react-native-firebase/app
    3
    4# link @react-native-firebase/crashlytics
    5npx react-native link @react-native-firebase/crashlytics

    Manual Linking

  2. firebase crashlytics additional steps

    — changes on projectname/android/build.gradle

    1// projectname/android/build.gradle
    2
    3buildscript {
    4 ...
    5 dependencies {
    6 ...
    7 classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
    8 ...
    9 }
    10}

    — changes projectname/android/app/build.gradle

    below code add on third line below com.google.gms.google-services

    1apply plugin: 'com.google.firebase.crashlytics' // add on third line below com.google.gms.google-services
    2...

Enable debug crash logs

when you want to test crashes on your debug mode. create firebase.json file on root level to project.

1// <project-root>/firebase.json
2{
3 "react-native": {
4 "crashlytics_debug_enabled": true
5 }
6}

Crash

Example to test crash using crashlytics

1import React, { useEffect } from 'react';
2import crashlytics from '@react-native-firebase/crashlytics';
3
4export default class crashlytics extends React.Component {
5
6 constructor(props) {
7 super(props);
8
9 }
10
11 componentDidMount() {
12 crashlytics().log('crash on componentDidMount.');
13 crashlytics().crash()
14 }
15}

Error log

Example to test error log using crashlytics

1import React, { useEffect } from 'react';
2import crashlytics from '@react-native-firebase/crashlytics';
3
4export default class crashlytics extends React.Component {
5
6 constructor(props) {
7 super(props);
8
9 }
10
11 componentDidMount() {
12 crashlytics().log('Error on componentDidMount');
13 crashlytics().recordError(error);
14 }
15}

Attributes

There are various methods to set attributes for the crash report, in order to provide analytics for crashes and help you review them.

1import React, { useEffect } from 'react';
2import crashlytics from '@react-native-firebase/crashlytics';
3
4export default class crashlytics extends React.Component {
5
6 constructor(props) {
7 super(props);
8
9 }
10
11 async reportError() {
12 crashlytics().log('Track errors.');
13 await Promise.all([
14 crashlytics().setAttribute('screenName', String('crashlytics')),
15 crashlytics().setAttributes({
16 fumctionName: 'reportError',
17 errorCode: 'ER1309',
18 }),
19 ]);
20
21 crashlytics().recordError(error);
22
23 }
24}

After following my own react native firebase crashlytics tutorial i got Execution failed for task ':react-native-firebase_crashlytics:generateDebugRFile' error.

Here, you will get solution How to solve react native firebase crashlytics generateDebugRFile failed issue?

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to delete SQLite database in android react native

how to delete and check SQLite database file using react native programmatically.

November 25th, 2020 · 1 min read

React Native Image

How to add an image to react native, statically, dynamically, and data base64.

November 8th, 2020 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]