[英]Disable Firebase in development mode in Android
I am using Firebase in my android project.我在我的 android 项目中使用 Firebase。 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?在开发模式下禁用它有什么更好的方法吗?
Checkout https://firebase.google.com/docs/analytics/configure-data-collection?platform=android结帐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在 app/build.gradle 中为调试和发布设置不同的布尔值
buildTypes {
debug {
resValue("bool", "FIREBASE_ANALYTICS_DEACTIVATED", "true")
}
release {
resValue("bool", "FIREBASE_ANALYTICS_DEACTIVATED", "false")
}
}
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有关更多详细信息,请查看https://firebase.google.com/support/guides/disable-analytics
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这篇博文详细介绍了您的选择: https : //firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html
public class MyApp extends Application {
public static boolean isDebuggable;
public void onCreate() {
super.onCreate();
isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
FirebaseCrash.setCrashCollectionEnabled(!isDebuggable);
}
}
Since Google Play Services / Firebase 11+, we can programmatically disable the Firebase Crashlytics at runtime.由于 Google Play Services / Firebase 11+,我们可以在运行时以编程方式禁用 Firebase Crashlytics。
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
To disable Firebase Crashlytics in Debug builds:要在调试版本中禁用 Firebase Crashlytics:
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);
or for better readability:或为了更好的可读性:
if(BuildConfig.DEBUG) {
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.