Search code examples
android-gradle-plugincrashlyticstwitter-fabriccrashlytics-android

Do I need to add gradle import in Android Studio for Fabric Answers if I'm already using Crashlytics?


Android Studio, Gradle, Fabric Crashlytics - we've got a pretty common setup. We have the usual compile line in build.gradle:

compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true;
}

And in our Application sub-class, the instantiating line:

Fabric.with(this, new Crashlytics());

All good. Working for a long time. Now we want to use Fabric Answers.

Here's the confusing part - if I edit the instantiating line to this:

Fabric.with(this, new Crashlytics(), new Answers());

.. it works. I was expecting that I would need to add the following to build.gradle, as their installation docs recommend:

compile('com.crashlytics.sdk.android:answers:1.3.10@aar') {
    transitive = true;
}

But the Answers class seems to be found with or without this import.

So, I guess my questions:

  1. Do I need both Gradle compile entries? Or is com.crashlytics.sdk.android:crashlytics:2.6.5@aar a super-set that already includes Answers?
  2. Is Fabric.with(this, new Crashlytics(), new Answers()); the correct way to instantiate things when I want both Crashlytics + Answers?

I'm using both Gradle imports, but it just seemed to compile OK even if I didn't have the second one. Kinda confused why.

Thanks!

UPDATE

As the accepted answer states, having Fabric.with(this, new Crashlytics()); alone is enough.

Digging into the Crashlytics class, it looks like it actually instantiates a few things:

this(new Answers(), new Beta(), new CrashlyticsCore());

.. so there you go! The extra Gradle import + Fabric instantiation argument are superfluous.


Solution

  • You don't need to explicitly add the Answers dependency to the build.gradle file since it's already included by default with Fabric. So your first line is fine Fabric.with(this, new Crashlytics());