3

Trying to implement two crash handlers with crashlytics (as discussed in Crashlytics Android SDK - custom UncaughtExceptionHandler) I can not get the intializationCalback to work - in Kotlin. Is somebody having the same issue or is there something wrong with my code? (To clarify: neither the success nor the failure method are ever called, hence the new UncaughtException Handler is also not executed)

val core = CrashlyticsCore.Builder()
    .build()
Fabric.with(
    Fabric.Builder(contextProvider.invoke()).kits(
        Crashlytics.Builder()
            .core(core)
            .build()
    ).initializationCallback(object : InitializationCallback<Fabric> {
        override fun success(fabric: Fabric) {
            var mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler()
            Thread.setDefaultUncaughtExceptionHandler { t, e ->
                Log.e("CrashLogger","Excpetion",e)
                mDefaultUEH.uncaughtException(t, e)
            }
        }

        override fun failure(e: Exception) {
            Log.e("CrashLogger", "Error during initialization ", e)
        }
    }
    ).build()
)
Blitz
  • 5,521
  • 3
  • 35
  • 53

1 Answers1

0

Tried almost same code in my application class but it worked for me, success() was called.

class MyApplication: MultiDexApplication() {
    override fun onCreate() {
        super.onCreate()
        val core = CrashlyticsCore.Builder()
            .build()
        Fabric.with(
            Fabric.Builder(this)
                .kits(Crashlytics.Builder().core(core).build())
                .initializationCallback(object: InitializationCallback<Fabric> {
                    override fun success(p0: Fabric?) {
                        Timber.d("InitializationCallback success")
                    }
                    override fun failure(p0: Exception?) {
                        Timber.d("InitializationCallback failure")
                    }
                })
                .build()
        )
        ...
    }
    ...
}

Check these

  • Check io.fabric.ApiKey in your AndroidManifest.xml
  • Check if your contextProvider.invoke() returns appropriate context
  • Try android.app.Application as context and see it works or not
taka
  • 1,407
  • 5
  • 7