2

I have integrated firebase Crashlytics on a react native application. I want to disable crash logs while working on development mode. How can I disable crash logs in debug mode for both Android and Ios Application. To create crash logs I have followed react native firebase documentation check this official link :: https://rnfirebase.io/docs/v5.x.x/crashlytics/android

I am using react-native-firebase version 5.2.2

I want to disable logs on debug mode without changing the version. I want to add code to disable the crash log for both Android and Ios. Please suggest how this should be done.

4 Answers 4

12

The documentation explains how to disable it

iOS

Turn off automatic collection with a new key to your Info.plist file:

Key: firebase_crashlytics_collection_enabled

Value: false

<key>firebase_crashlytics_collection_enabled</key>
<false/>

Android

Turn off automatic collection with a meta-data tag in your AndroidManifest.xml file:

<meta-data
    android:name="firebase_crashlytics_collection_enabled"
    android:value="false" />

Enable collection at runtime

You can can initialise crashlytics in your javascript code using

firebase.crashlytics().enableCrashlyticsCollection();

You can then use

if (__DEV__) {

} else {

}

to run any specific code in development or in production.

Sign up to request clarification or add additional context in comments.

7 Comments

I have imported firebase , and initialized crashlytics when app is running in debug mode, but it shows me an error :: _reactNativeFirebase.default.crashlytics(...).enableCrashlyticsCollection is not a function
Did you add the values to your Info.plist and AndroidManifest.xml? As I do not get that error when I do it in my set up.
I am working on Android and added code inside AndroidManifest.xml file <meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
Do I need to import anything else except firebase inside my react js file ??
I am doing nothing more than import firebase from 'react-native-firebase'; then calling if(__DEV__) { firebase.crashlytics().enableCrashlyticsCollection(); } obviously with the edits to the AndroidManifest.xml and Info.plist. Only thing I can think of is that you haven't put the meta-data in the correct place in your AndroidManifest.xml
|
1

I only need to set one line in firebase.json file,

{
    "react-native": {
        "crashlytics_debug_enabled": false
    }
}

1 Comment

0

faced the same in one of my project : "react-native": "0.66.1"

  1. Edit AndroidManifest.xml

     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.reversedomain">
      <application
        ...
        ...
       // add this line
      <meta-data
      android:name="firebase_crashlytics_collection_enabled"
       android:value="false" />
    
    </application>
    
  1. install '@react-native-firebase/crashlytics'

  2. add .env at the root of your project & set production = false

  3. in app.js

    import React from 'react'
    import { production } from '@env';
    import crashlytics from '@react-native-firebase/crashlytics';
    
    useEffect(()=>{
     if (production == true) {
      // Enable on runtime
     crashlytics().setCrashlyticsCollectionEnabled(true);
    }
    },[])
    
  4. docs

Comments

0

The new way to do it, is just add this in your firebase.json

// <project-root>/firebase.json
{
  "react-native": {
    "crashlytics_auto_collection_enabled": false
  }
}

And enable crashlytics collection at runtime:

  if (!__DEV__) {
      crashlytics().setCrashlyticsCollectionEnabled(true)
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.