[英]Android: Disabling crashlytics for debug build
I just wanted to disable crashlytics for debug build.我只是想为调试版本禁用 crashlytics。
So I followed the instruction in their official document.所以我按照他们官方文件中的说明进行操作。 https://docs.fabric.io/android/crashlytics/build-tools.html
https://docs.fabric.io/android/crashlytics/build-tools.html
According to the document, I have to do followings so I did it.根据文件,我必须做以下事情,所以我做到了。 First I added below,
首先我在下面添加,
android {
buildTypes {
debug {
// Disable fabric build ID generation for debug builds
ext.enableCrashlytics = false
...
And I added below into my Application class.我将下面添加到我的应用程序类中。
// Set up Crashlytics, disabled for debug builds
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);
But I still get this error.但我仍然收到这个错误。
Caused by: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
Is there something that I'm missing?有什么我想念的吗?
I checked that the build type that I was trying to build and it worked well before without this configuration.我检查了我尝试构建的构建类型,并且在没有此配置的情况下它运行良好。
My crashlytics version is 2.9.4.我的 crashlytics 版本是 2.9.4。
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
Thanks!谢谢!
To disable Firebase before your application starts, you need to add the following code to your AndroidManifest.xml:要在您的应用程序启动之前禁用 Firebase,您需要将以下代码添加到您的 AndroidManifest.xml 中:
<application
... >
...
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="${crashlyticsCollectionEnabled}" />
</application>
The expression ${crashlyticsCollectionEnabled} is called manifest placeholder and its value comes from your main module's build.表达式 ${crashlyticsCollectionEnabled} 称为清单占位符,其值来自主模块的构建。 gradle file:
毕业文件:
android {安卓 {
...
buildTypes {
debug {
manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
...
}
release {
manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
...
}
}
} }
Looks like you are missing API Key , if yes then add in manifest file under application tag, like below看起来您缺少API Key ,如果是,则在应用程序标签下添加清单文件,如下所示
<application
.........
.........
<meta-data
android:name="io.fabric.ApiKey"
android:value="<FABRIC_API_KEY>"
/>
</application>
Well, now that I look at your code it looks like there is definitely a better solution for that than the way I am doing it, but the approach I am using works very well so I will share it anyway (I am using only two build types: DEBUG and RELEASE and no variants, so it is sufficient for me).好吧,现在我查看了您的代码,看起来肯定有比我这样做的方式更好的解决方案,但是我使用的方法效果很好,所以无论如何我都会分享它(我只使用两个构建类型:DEBUG 和 RELEASE,没有变体,所以对我来说已经足够了)。 I am simply not initializing the Crashlytics altogether (in
MyApp#onCreate
) when BuildConfig.DEBUG == True
当
BuildConfig.DEBUG == True
时,我根本没有完全初始化 Crashlytics(在MyApp#onCreate
)
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
}
}
}
But I am sure somebody else with come up with better solution.但我相信其他人会提出更好的解决方案。
In your app level build.gradle add this :在您的应用级别 build.gradle 中添加以下内容:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
dependencies {
compile('com.crashlytics.sdk.android:crashlytics:KIT_VERSION@aar') {
transitive = true;
}
}
android {
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
production {
buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'false'
}
fabricOn {
buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'false'
}
fabricOff {
buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'true'
}
}
}
Add below line in your application class onCreate method:(note: this is in kotlin convert it to java)在您的应用程序类 onCreate 方法中添加以下行:(注意:这是在 kotlin 中将其转换为 java)
val core = CrashlyticsCore.Builder().disabled(BuildConfig.IS_FABRIC_DISABLED).build()
Fabric.with(this, Crashlytics.Builder().core(core).build())
After adding this you will see in left side Build Variants with diffrent option.添加后,您将在左侧看到具有不同选项的构建变体。 (here I didn't apply fabric option it shows default option)
(这里我没有应用面料选项,它显示了默认选项)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.