41

Looking for some help. I just upgraded my android app to fabric and now the app gives an error on this line:

Crashlytics.start(getApplicationContext());

Gradle: error: cannot find symbol method start(Context)

I tried commenting out that line, but then the crashes are not getting logged. How do I initialize Crashlytics in the new fabric framework? Am I missing something?

Thanks in advance for your help.

tobltobs
  • 2,782
  • 1
  • 27
  • 33
Nidhi Shah
  • 568
  • 2
  • 7
  • 14
  • Fabric injected this line of code in the launcher activity without deleting the earlier code from the application file. Hence all the confusion. Delete this line from your ptoject: Crashlytics.start(getApplicationContext()); to resolve the issue. – Nidhi Shah Dec 06 '14 at 23:50

2 Answers2

84

Since Crashlytics is now part of Fabric the initialization process has changed, but is still simple. Instead of using Crashlytics.start() you should now use, but in the Application creation:

public class App extends Application {

    ...

    @Override
    public void onCreate() {
        super.onCreate();
        Fabric.with(this, new Crashlytics());
    }

    ...

}

For a more richer example, see how Cannonball canonical sample app is doing:

public class App extends Application {

    ...

    private TwitterAuthConfig authConfig;

    ...

    @Override
    public void onCreate() {
        super.onCreate();
        authConfig = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET);
        Fabric.with(this, new Crashlytics(), new Twitter(authConfig), new MoPub());
    }

    ...

}

This code is available at: https://github.com/twitterdev/cannonball-android/blob/master/app/src/main/java/io/fabric/samples/cannonball/App.java#L96-L98

bryant1410
  • 5,540
  • 4
  • 39
  • 40
Cipriani
  • 1,870
  • 14
  • 15
  • 6
    Where did you get this information? Found nothing about it in the official documentation. – akhy Dec 04 '14 at 11:15
  • @akhyar probably the cannonball sample app that was revealed in the Twitter conference where they announced Fabric – CQM Dec 04 '14 at 17:23
  • 1
    Can I later (after Fabric.with(this, new Crashlytics()); call) use smth like this: Crashlytics.setString("key", "value"); ??? – Dmitry Isakov Apr 22 '15 at 15:53
  • @Luis Cipriani Can you help me to resolve this issue http://stackoverflow.com/questions/33126132/could-not-install-digits-kit-in-eclipse-using-fabric-plugin – SSS Oct 15 '15 at 07:41
  • Do i have to add Fabric.with(this, new Crashlytics()) inside evry activity's oncreate method ?? – Sudhanshu Gaur Apr 26 '16 at 16:15
  • Do you know please why the active session is always null in my case? This is how I check the session: TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession(); and Fabric is initialized like that: TwitterAuthConfig authConfig = new TwitterAuthConfig(twitterKey, twitterSecretKey); Fabric.with(this, new Twitter(authConfig)); – Ne AS Mar 29 '17 at 08:41
  • @Luis Cipriani,can you tell me if we include Fabric.with(this, new Crashlytics()); inside application class do we still need to add Fabrid.with() in every Activity? – Jay Dangar Sep 06 '18 at 09:22
2

In latest version init is done automatically by ContentProvider https://firebase.google.com/docs/crashlytics/upgrade-sdk?platform=android

 import com.google.firebase.crashlytics.FirebaseCrashlytics

// ...

// Explicit initialization of Crashlytics is no longer required.

// OPTIONAL: If crash reporting has been explicitly disabled previously, add:
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)
Andrii Kovalchuk
  • 4,351
  • 2
  • 36
  • 31