简体   繁体   English

在 Android 的开发模式下禁用 Firebase

[英]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.

相关问题 为 Android 禁用 firebase crashlytics - Disable firebase crashlytics for Android Firebase 登录错误仅在 android 发布模式下 - Firebase SignIn error only in android release mode 如何从共享首选项 (Android) 禁用 boolean 上的 Firebase 消息传递 - How to disable Firebase Messaging on boolean from Shared Preferences (Android) 有什么方法可以从 android 工作室的代码中禁用 firebase 帐户 - is there is any way to disable firebase account from code in android studio Flutter Android firebase 通知在发布模式下不起作用 - Flutter Android firebase notification doesn't work in release mode 在本机模式下禁用 Firestore - Disable Firestore in native mode Firebase 开发生产中 URL - Firebase Action URL in development and production 在发布模式下使用 firebase auth 在 Android 上登录失败。 DEBUG 模式正常。 代码=10,消息=10,mPendingCredential=null - Failure to login using firebase auth on Android in release mode. DEBUG mode is OK. Code=10, message=10,mPendingCredential=null vue App环境变量在开发模式下可以读取,生产模式下不能读取 - Vue App environment variables can be read in development mode but not in production mode 如何在 AWS Elasticache Redis 上禁用集群模式 - How to disable cluster mode on a AWS Elasticache Redis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM