禁用Android的Firebase crashlytics [英] Disable firebase crashlytics for Android
问题描述
我正在开发一个android应用,并集成了firebase和firebase crashlytics SDK。
I am developing an android app and have integrated the firebase and firebase crashlytics SDK.
我想允许用户禁用崩溃报告(以确保GDPR符合性-我认为崩溃报告与GDPR相关),因此需要一种方法使用户能够通过应用程序设置禁用它。
I want to allow the user to disable crash reporting (to ensure GDPR compliance - I assume crash reports are related to GDPR) so need a way for the user to be able to disable it via the apps settings.
我在 https中找到了文档://firebase.google.com/docs/crash/disable-sdk ,但是当我尝试并执行以下操作时:
I found the docs at https://firebase.google.com/docs/crash/disable-sdk but when I try and the line:
FirebaseCrash.setCrashCollectionEnabled(true);
Android Studio给我错误无法解析符号'FirebaseCrash'
Android Studio gives me the error cannot resolve symbol 'FirebaseCrash'
这需要在应用运行时以编程方式完成。
This needs to be done programatically at runtime of the app.
推荐答案
在运行时禁用Crashlytics
Disable Crashlytics at runtime
// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
Fabric.with(this, crashlyticsKit);
Ex
Ex
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
Fabric.with(this, crashlyticsKit);
setContentView(R.layout.activity_main);
}
更多
More
boolean Agrees = value;
if(Agrees)
{
Fabric.with(this,new Crashlytics());
}
else
{
CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(true).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());
throw new RuntimeException("why doesn't this show up in Firebase Crashlytics?");
}
编辑2
参考:无法通过DEBUG构建版本禁用带有Firebase的Fabric的Crashlytics
The < href = https://firebase.google.com/docs/crashlytics/customize-crash-reports#enable_opt_in_reporting rel = noreferrer> Firebase Crashlytics文档解释说,一旦在应用会话中启用了报告,
The Firebase Crashlytics documentation explains that once reporting is enabled in an app session, it cannot be disabled.
默认情况下,在名为 CrashlyticsInitProvider ContentProvider 中启用了Crashlytics报告。在创建 Application
实例之前执行的em>。 CrashlyticsInitProvider 根据元数据值 firebase_crashlytics_collection_enabled
启用或禁用报告,该值默认为true。
By default, Crashlytics reporting is enabled in a ContentProvider
named CrashlyticsInitProvider that executes before your Application
instance is created. CrashlyticsInitProvider enables or disables reporting based on the meta-data value firebase_crashlytics_collection_enabled
, which by default is true.
如果要禁用报告功能,则必须提供清单元数据并将其设置为false,这一点至关重要:
If you want reporting disabled, it's critical that the manifest meta-data be present and set to false:
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
在应用初始化期间查看消息中的logcat:
Look in the logcat during app initialization for the message:
CrashlyticsInitProvider: CrashlyticsInitProvider initialization successful
如果消息存在时, firebase_crashlytics_collection_enabled
为真。如果消息不存在,则说明您已成功将元数据设置为禁用崩溃报告。
If the message is present, firebase_crashlytics_collection_enabled
is true. If the message is not present, you have successfully set the meta-data to disable crash reporting.
如果元数据丢失或设置为true,则无法禁用通过调用 Fabric.with(...)
在代码中进行报告。
If the meta-data is missing or set to true, you cannot disable reporting in your code using a call to Fabric.with(...)
.
在另一个注释中回答,表明您尝试使用元数据禁用报告,但未成功。检查输入错误,并确保将声明正确放置在< application>
元素中。在测试中,我可以使用元数据禁用报告,然后在运行时启用。
In a comment to another answer, you indicate that you tried disabling reporting using the meta-data and were not successful. Check for a typo and ensure the declaration is correctly placed in the <application>
element. In my tests, I am able to disabling reporting using the meta-data and then enable at run time.
这篇关于禁用Android的Firebase crashlytics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!