Disable Firebase in development mode in Android

15,262

Solution 1

Checkout https://firebase.google.com/docs/analytics/configure-data-collection?platform=android

<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />

To do this automatically add the following line to manifest:

 <meta-data
        android:name="firebase_analytics_collection_deactivated"
        android:value="@bool/FIREBASE_ANALYTICS_DEACTIVATED"/>

Set different value of boolean for debug and release in your app/build.gradle

buildTypes {
    debug {
        resValue("bool", "FIREBASE_ANALYTICS_DEACTIVATED", "true")
    }
    release {
        resValue("bool", "FIREBASE_ANALYTICS_DEACTIVATED", "false")
    }
}

Solution 2

Add this line to your manifest file while development.

<meta-data android:name="firebase_analytics_collection_deactivated" android:value="true" />

For more details check https://firebase.google.com/support/guides/disable-analytics

Solution 3

It would be better to separate your dev and prod environments instead of disabling things completely. You have options on how to implement this, so you can choose what suits your team the best. This blog post details your options: https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html

Solution 4

    public class MyApp extends Application {
        public static boolean isDebuggable;

        public void onCreate() {
            super.onCreate();
            isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
            FirebaseCrash.setCrashCollectionEnabled(!isDebuggable);
        }
    }
Share:
15,262

Related videos on Youtube

Faisal Memon
Author by

Faisal Memon

Technology enthusiast, Java, Android, Web, OBIEE Developer ;)

Updated on June 11, 2022

Comments

  • Faisal Memon
    Faisal Memon about 2 years

    I am using Firebase in my android project. Wanted to know how to disable it in development mode. All crashes and usage/events are being logged and messing up with actual analytics.

    Any better way to disable this in development mode?

    • ugur
      ugur almost 8 years
      As far as i know only option to create 2 different projects for dev and prod environments
    • Faisal Memon
      Faisal Memon almost 8 years
      :( No better way?
    • Frank van Puffelen
      Frank van Puffelen almost 8 years
      That is the better way. But otherwise see stackoverflow.com/questions/37518212/…
  • Leon
    Leon over 6 years
    Even better, add a property to Gradle to handle it automatically: resValue("bool", "FIREBASE_ANALYTICS_DEACTIVATED", "true") such as was suggested for Crashlytics here: stackoverflow.com/a/44452585/945247
  • user924
    user924 over 2 years
    how to enable it back?
  • Tom S
    Tom S over 2 years
    Thanks! I also had to add tools:replace="android:value" to the AndroidManifest.xml part: (if using react-native-firebase) eg: <meta-data tools:replace="android:value" android:name="firebase_analytics_collection_deactivated" android:value="@bool/FIREBASE_ANALYTICS_DEACTIVATED"/>