Damandroid
Damandroid

Reputation: 984

Crashlytics.logException method throwing illegal state exception. Not able to collect non-fatal issues for some activities

My app uses the above Firebase Crashlytics feature but I am running into a strange problem. Recently I saw in my app's playstore crashes, an exception (see attached photo). Crash Description The corresponding code in that location is as follows:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_sites)
        setSupportActionBar(findViewById(R.id.my_toolbar))

        init()
        try{
            loadSitesSetAdapter()
        } catch (e:NullPointerException){
            Crashlytics.logException(e) // this is line 55 as crash
            finish()
//            startActivity(Intent(this,MainActivity::class.java))
        }

The Fabric initialisation is as follows in my app:

in app level gradle I have:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        // Disable fabric build ID generation for debug builds
        ext.enableCrashlytics = false
    }
}

In main activity I have the following:

val crashlyticsKit = Crashlytics.Builder()
                                    .core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
                                    .build();

    // Initialize Fabric with the debug-disabled crashlytics.
    Fabric.with(this,crashlyticsKit)

and last but not the least my dependency in gradle file is as follows:

// Crashlytics
implementation('com.crashlytics.sdk.android:crashlytics:2.9.8@aar') {
    transitive = true;
}

Is there something obvious I am missing here? Help please

Upvotes: 1

Views: 725

Answers (1)

joelreeves
joelreeves

Reputation: 1954

Fabric has to be initialized before it can be used in an app. Where you are calling Crashlytics.logException(e), is that done before the line Fabric.with(this,crashlyticsKit)? If not then, you have to initialize Fabric before you can use any of its methods.

If you're going to be calling Fabric methods in multiple activities/screens, then it's best to have an Application subclass where you can initialize Fabric.

See the getting started paragraph here: https://docs.fabric.io/android/fabric/overview.html#manual-setup

Upvotes: 2

Related Questions