9

Disabling Crashlytics error reporting is relatively straight forward.. I'd also like to disable Answers for debug builds. However,

new Crashlytics.Builder().answers(null);

doesn't work since apparently answers can't be null and

new Crashlytics.Builder().answers(new CustomAnswers());

with CustomAnswers being my class extending Answers gets me a NPE when calling Answers.getInstance(). But that approach is cumbersome to begin with compared to simply calling some enable() method.

Any ideas?

On a side note, I really hope Fabric is going to update and improve their docs soon.

Community
  • 1
  • 1
jbxbergdev
  • 860
  • 1
  • 10
  • 23
  • 3
    Hey there, Mike from Fabric here. Awesome to know you'd like to disable Answers on debug builds. Right now, Answers is enabled for all builds, but I'll let the team know you'd like to be able to do this. Let me know what improvements you'd like to see to our docs here: http://docs.fabric.io/index/fabric – Mike Bonnell Aug 13 '15 at 01:08
  • Hi Mike, thanks for your reply. What about introducing an Answers.Builder class à la CrashlyticsCore.Builder? It's already possible to pass an Answers object into Crashlytics, but that doesn't seem to work as intended. On the docs: I would really like to see a real javadoc for the current version. Also, the information is a) a bit scattered between the docs page and the "knowledge base" ad b) the docs in some places seem to be targeting old versions. – jbxbergdev Aug 13 '15 at 06:06
  • Thanks, you can head to docs.fabric.io for our latest documentation and the Javadocs are here: http://docs.fabric.io/android/javadocs.html – Mike Bonnell Aug 13 '15 at 17:20
  • 1
    hi @MikeB how to disable answer in iOS? – Rajneesh071 Nov 27 '15 at 06:22
  • @Rajneesh071 it would be good to know more details about what you're looking to do and how you're looking to do it! – Mike Bonnell Dec 01 '15 at 01:31
  • we are continuously getting emails of answers even after disabling .. – Rajneesh071 Dec 01 '15 at 07:26
  • 2
    Yeah, I REALLY REALLY HATE the constant animation of flying blocks on the Answers part of the Crashlytics website. This is nothing but irritating visual distraction. I want to disable Answers now that I enabled it simply because of this. This is just worse than useless, is terribly distracting and simply very very bad. – Alex Zavatone Oct 28 '16 at 13:18

3 Answers3

4

on my app we do it the old fashioned way:

if (!IS_DEBUG) {
   Fabric.with(this, new Crashlytics());
}

works fine.

Of course you can initialise with whichever custom parameters you need.

edit:

to get the debug boolean is just a matter of using gradle to your favour:

src/
   main/ // your app code
   debug/
       AppSettings.Java:
            public static final boolean IS_DEBUG = true;
   release/
       AppSettings.Java:
            public static final boolean IS_DEBUG = false;

edit:

I would advise against using BuildConfig.DEBUG, see this article: http://www.digipom.com/be-careful-with-buildconfig-debug/

Budius
  • 39,391
  • 16
  • 102
  • 144
  • 2
    Thanks, but this gets me an IllegalStateException when calling Answers methods further down the road. – jbxbergdev Aug 12 '15 at 11:43
  • I've just further check my code, we're always checking `if(!AppSettings.IS_DEBUG)` before calling any Crashlytics method. Sorry it was not more helpful, if you find a more automated way of dealing with it, let me know. – Budius Aug 12 '15 at 11:47
  • 1
    FYI, `BuildConfig.DEBUG` has always worked properly for Gradle builds. That bug was only present in ADT. – Jarett Millard Mar 02 '16 at 15:26
  • 1
    The blog you linked to was dated 2012.. there is no reason to define your own debug flag.. just use BuildConfig.DEBUG thats what its for. – Greg Ennis Apr 24 '16 at 01:54
3

For the time being, I solved the problem the old Java way:

Extend Answers using a sort-of singleton:

public class CustomAnswers extends Answers {

    private static CustomAnswers instance;

    private boolean mEnabled;

    private CustomAnswers(boolean enabled) {
        super();
        mEnabled = enabled;
    }

    public static synchronized void init(boolean enabled) {
        if (instance == null) {
            instance = new CustomAnswers(enabled);
        }
    }

    public static synchronized CustomAnswers get() {
        return instance;
    }

    @Override
    public void logSignUp(SignUpEvent event) {
        if (mEnabled) {
            super.logSignUp(event);
        }
    }

    // (...)
}

Initialize Crashlytics with Answers implementation:

boolean isDebug = DebugHelper.isDebugVersion(this);
CustomAnswers.init(!isDebug);
CrashlyticsCore crashlyticsCore =
        new CrashlyticsCore.Builder().disabled(isDebug).build();
Fabric.with(this, new Crashlytics.Builder()
        .core(crashlyticsCore).answers(CustomAnswers.get()).build());

Use Answers implementation for events:

CustomAnswers.get().logInvite(new InviteEvent());

This will disable events being logged.

Note that, as described in my first post, Answers.getInstance() will return null and not your CustomAnswers instance in that case.

Sufian
  • 6,405
  • 16
  • 66
  • 120
jbxbergdev
  • 860
  • 1
  • 10
  • 23
-1

Try this code

 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());
sasikumar
  • 12,540
  • 3
  • 28
  • 48
  • 3
    That's my current setup. But it only affects crash reporting, not Answers (Answers is always enabled regardless of the disabled() setting). – jbxbergdev Aug 12 '15 at 12:30