Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

android - How to disable Crashlytics during development

Is there any simple way to turn Crashlytics Android SDK off while developing ?

I don't want it to send a crash every time I do something stupid

On the other hand I don't want to comment out Crashlytics.start() and possibly risk forgetting to uncomment it and commit

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the solution from Crashlytics (with Fabric integration)

Put following code inside your Application class onCreate()

Crashlytics crashlytics = new Crashlytics.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, crashlytics);

EDIT:

In Crashalitics 2.3 and above, this is deprecated. The correct code is:

CrashlyticsCore core = new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, new Crashlytics.Builder().core(core).build());

or

Fabric.with(this, new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build());

(copied from Crashlytics deprecated method disabled())


EDIT2:

You can also optionally add this to your buildType in gradle. This command disables sending the crashlytics mapping file and generating an ID for each build, which speeds up gradle builds of those flavors. (It doesn't disable Crashlytics at run time.) See Mike B's answer here.

buildTypes {
    release {
           ....
    }
    debug {
        ext.enableCrashlytics = false
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...