Reputation: 774
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?
Upvotes: 30
Views: 20514
Reputation: 270
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="${crashlyticsCollectionEnabled}" />
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="${analyticsCollectionEnabled}" />
buildTypes {
debug {
manifestPlaceholders["crashlyticsCollectionEnabled"] = false
manifestPlaceholders["analyticsCollectionEnabled"] = false
}
release {
manifestPlaceholders["crashlyticsCollectionEnabled"] = true
manifestPlaceholders["analyticsCollectionEnabled"] = true
}
}
you can check from Firebase Analytics - Firebase Crashlytics - Inject build variables into the manifest
Upvotes: 1
Reputation: 973
Since Google Play Services / Firebase 11+, we can programmatically disable the Firebase Crashlytics at runtime.
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
To disable Firebase Crashlytics in Debug builds:
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);
or for better readability:
if(BuildConfig.DEBUG) {
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
}
Upvotes: 1
Reputation: 936
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")
}
}
Upvotes: 58
Reputation: 7710
public class MyApp extends Application {
public static boolean isDebuggable;
public void onCreate() {
super.onCreate();
isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
FirebaseCrash.setCrashCollectionEnabled(!isDebuggable);
}
}
Upvotes: 1
Reputation: 409
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
Upvotes: 19
Reputation: 317467
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
Upvotes: 5