新的 Firebase Crashlytics 在调试模式下禁用

New Firebase Crashlytics disable in debug mode

我最近从 Fabric one 切换到新的 Firebase Crashlytics,但找不到在调试模式下禁用 Crashlytics 的替代方法。

面料:

val crashlytics = Crashlytics.Builder().core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build()
Fabric.with(this, crashlytics, Answers())

有人知道答案吗?我看到 FirebaseCrashlytics class 现在已经在内部建立了核心。我试过 FirebaseCrashlytics(CrashlyticsCore.??).getInstance(),但那种构造函数不起作用。

另外 CrashlyticsCore class 不再有 .Builder() 可用

我前段时间试过一次,对我有用。将此添加到 build.gradle.

android {
  buildTypes {
     debug {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
        ...
     }

    release {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
        ...
    }
  }
}

然后在清单中设置这个属性。

<meta-data
        android:name="firebase_crashlytics_collection_enabled"
        android:value="${crashlyticsCollectionEnabled}" />

如果您也手动登录,那么您可以在运行时使用类似这样的东西:-

FirebaseCrashlytics.getInstance().recordException(RuntimeException("Invalidtoken"))

还有Check this out .

要以编程方式执行此操作,请在应用程序中使用以下代码 class

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG)
//enabled only for signed builds

Enable collection for select users by calling the Crashlytics data collection override at runtime. The override value persists across launches of your app so Crashlytics can automatically collect reports for future launches of that app instance. To opt out of automatic crash reporting, pass false as the override value. When set to false, the new value does not apply until the next run of the app.

这是 link 文档 https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#enable-reporting