1

I have found glitch in crashlytics/fabric initialization. As Mike from crashlytics suggests here: how to initialize new fabric we should use:

Fabric.with(this, CrashlyticsCore.getInstance());

But when i switched to androidX it started crashing with:

Must Initialize Fabric before using singleton()

Some of my main settings is:

compileSdkVersion 29
targetSdkVersion 29
io.fabric.tools:gradle:1.28.1
gradle: 5.5.1
com.crashlytics.sdk.android:crashlytics:2.10.0@aar

In onCreate in my Application class:

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

Of course i have metadata in manifest:

<meta-data
    android:name="io.fabric.ApiKey"
    android:value="myKey"/>
Kebab Krabby
  • 1,574
  • 13
  • 21

3 Answers3

1

This initialization works like a charm without any problems.

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

But i dont understand why the newer fails.

Kebab Krabby
  • 1,574
  • 13
  • 21
1

In case you haven't register your app in manifest file, Try this:

In your AndroidManifest.xml:

<application
    android:name=".MyApplication"
    ...
    />

And try initializing like this:

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        val core = CrashlyticsCore.Builder().disabled(false).build()
        Fabric.with(this, Crashlytics.Builder().core(core).build())
    }
}

This is what I use in my projects and it works perfectly!

Birju Vachhani
  • 6,072
  • 4
  • 21
  • 43
1

Mike's answer is incorrect from that link. When you use below initialisation

Fabric.with(this, CrashlyticsCore.getInstance());

CrashlyticsCore.getInstance() this getInstance method is trying to access Fabric class object which hasn't been created. Fabric object is created in with method which will be called once CrashlyticsCore.getInstance()is executed

Solution :

You can use any of below lines for initialisation since they're creating all objects using new keyword

Fabric.with(this, new Crashlytics());
Fabric.with(this, new CrashlyticsCore());
Fabric.with(this, new CrashlyticsCore(), new Crashlytics())
Bali
  • 749
  • 6
  • 19