Navigate back to the homepage

Implement react native firebase crashlytics on android

Infinitbility
Firebase, React Native
December 12th, 2020 · 1 min read
Implement react native firebase crashlytics on android

Hello Friends,

Welcome To Infinitbility!

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, acept 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}

if you get help, please share a post on your social network

More From React Native Tutorial

Basics

  1. Introduction To React Native
  2. React Native Environment Setup using expo
  3. React Native Environment Setup for windows
  4. React Native Environment setup on Mac OS
  5. React Native Environment setup on linux
  6. React Native Project Structure
  7. React Native State
  8. React Native Props
  9. React Native Styling
  10. React Native Flexbox
  11. React Native Text
  12. React Native Textinput
  13. React Native Commands
  14. React Native ScrollView

Advances

  1. React Native Dark Mode
  2. React Native Fonts
  3. React Native SQLite
  4. React Native DatepickerAndroid
  5. React native ScrollView scroll to position
  6. How to align icon with text in react native
  7. React Native Image
  8. React Native Firebase Crashlytics
  9. React Native Async Storage
  10. React Native Share

Error & Issue Solution

  1. Task :app:transformDexArchiveWithDexMergerForDebug FAILED In React Native
  2. Expiring Daemon because JVM heap space is exhausted In React Native
  3. Task :app:transformNativeLibsWithMergeJniLibsForDebug FAILED In React Native
  4. Unable to determine the current character, it is not a string, number, array, or object in react native
  5. App crashed immediately after install react native video or track player
  6. how to delete SQLite database in android react native
  7. React native material dropdown twice click issue
  8. How to get the current route in react-navigation?
  9. how to disable drawer on the drawer navigation screen?
  10. Image not showing in ios 14 react native
  11. React Native image picker launchimagelibrary on second time issue
  12. how to open any link from react native render Html

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]

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.

More articles from Infinitbility

how to delete SQLite database in android react native

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

React Native Image

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

November 8th, 2020 · 1 min read
© 2020–2021 Infinitbility
Disclaimer
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]