有没有什么简单的方法可以在开发过程中关闭Crashlytics Android SDK ?
我不希望每次我做一些愚蠢的事情时它都会崩溃
另一方面,我不想注释掉Crashlytics.start(),可能会忘记取消注释并提交
有没有什么简单的方法可以在开发过程中关闭Crashlytics Android SDK ?
我不希望每次我做一些愚蠢的事情时它都会崩溃
另一方面,我不想注释掉Crashlytics.start(),可能会忘记取消注释并提交
当前回答
如果你想要一个可调试的版本,方法如下:
buildTypes {
release {
signingConfig signingConfigs.config
debuggable true //-> debuggable release build
minifyEnabled true
multiDexEnabled false
ext.enableCrashlytics = true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'boolean', 'BUILD_TYPE_DEBUG', 'false'
}
debug {
minifyEnabled false
multiDexEnabled true
ext.enableCrashlytics = false
ext.alwaysUpdateBuildId = false
// Disable fabric build ID generation for debug builds
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'boolean', 'BUILD_TYPE_DEBUG', 'true'
}
}
当你将debuggable设置为true时,你的BuildConfig。DEBUG将初始化为true,这就是为什么我在BuildConfig类中添加了这个变量。
Init织物:
Crashlytics crashlytics = new Crashlytics.Builder()
// disable crash reporting in debug build types with custom build type variable
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.BUILD_TYPE_DEBUG).build())
.build();
final Fabric fabric = new Fabric.Builder(this)
.kits(crashlytics)
//enable debugging with debuggable flag in build type
.debuggable(BuildConfig.DEBUG)
.build();
// Initialize Fabric with the debug-disabled crashlytics.
Fabric.with(fabric);
其他回答
Add this to your app’s build.gradle: android { buildTypes { debug { // Disable fabric build ID generation for debug builds ext.enableCrashlytics = false ... Disable the Crashlytics kit at runtime. Otherwise, the Crashlytics kit will throw the error: // Set up Crashlytics, disabled for debug builds // Add These lines in your app Application class onCreate method Crashlytics crashlyticsKit = new Crashlytics.Builder() .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()) .build(); // Initialize Fabric with the debug-disabled crashlytics. Fabric.with(this, crashlyticsKit); In AndroidManifest.xml, add <meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />
我们可以使用fabric的isDebuggable()方法。
import static io.fabric.sdk.android.Fabric.isDebuggable;
if(! isDebuggable()){
// set Crashlytics ...
}
快乐编码:)
你可以使用一个专用的清单文件调试模式(适用于我与Crashlytics 2.9.7):
创建文件app/src/debug/AndroidManifest.xml并添加以下内容:
<application>
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false"/>
</application>
注意,这个元数据元素必须放在debug/AndroidManifest.xml中,而不是放在常规的AndroidManifest.xml中
使用CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()的解决方案不适合我,我发现crashlytics是由CrashlyticsInitProvider在application . oncreate()被调用或任何活动启动之前初始化的,这意味着在应用程序或活动中手动初始化fabric没有效果,因为fabric已经初始化。
如果你使用Gradle,只需添加这个到一个风味:
ext.enableCrashlytics = false
这对我来说很有用:
releaseCompile 'com.crashlytics.sdk.android:crashlytics:2.9.9'
和在buildTypes:
debug {
ext.enableCrashlytics = false
}