问题描述
这是我的应用类
class App : MultiDexApplication() {
override fun onCreate() {
FirebaseApp.initializeApp(this)
Thread.setDefaultUncaughtExceptionHandler(GoExceptionHandler(this))
super.onCreate()
}
}
&这里是ExceptionHandler
class GoExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandler {
override fun uncaughtException(p0: Thread,p1: Throwable) {
class GoExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandler {
override fun uncaughtException(p0: Thread,p1: Throwable) {
AmplitudeAnalyticsTracker.sendCrashEvent(p1.localizedMessage!!)
// Clearing Cache & data if crash occurrence more than 2 time
if (LocalPreference.getCrashCount() >= 3) {
context.cacheDir.deleteRecursively()
(context.getSystemService(MultiDexApplication.ACTIVITY_SERVICE) as ActivityManager)
.clearapplicationUserData()
} else {
LocalPreference.setCrashCount()
}
}
}
}
}
当我评论 Thread.setDefaultUncaughtExceptionHandler(GoExceptionHandler(this))
时,Crashlytic 控制台中的崩溃报告正确,但是当我将其添加到我的 APP 类时,它变成了噩梦,并且没有关于 firebase 的崩溃报告
解决方法
这是基于您的代码有缺陷的业务逻辑(您禁用了崩溃报告);否则 Crashlytics 将成为默认 UncaughtExceptionHandler
。如果您仍想向 Crashlytics 报告,则需要在方法 Exception
中记录 uncaughtException()
:
FirebaseCrashlytics.getInstance().recordException(p1)
,
Crashlytics 等崩溃报告服务通常使用 UncaughtExceptionHandler
来捕获和报告崩溃。只能有一个 UncaughtExceptionHandler
,因此如果您设置自己的,它将替换任何现有的。
要同时激活 Crashlytics 和您自己的处理程序,请让您自己的处理程序通过 getUncaughtExceptionHandler()
查询现有处理程序,并通过自己调用将崩溃处理委托给它。