注册 UncaughtExceptionHandler 不需要 URL: - CrashCapture.start 移除 logApiUrl 参数,只需 appContext + appKey - LogStorage.saveCrash 移除 logApiUrl,崩溃文件不再存储 URL - LogQueue.uploadPendingCrashes 上传时直接取 XuqmSDK.bugCollectApiUrl, URL 为 null 则跳过(下次启动重试),不依赖崩溃文件里的历史 URL - BugCollect.startCrashCapture 移除 URL 构造逻辑 - BugCollectInitProvider Phase 1 纯粹只注册,彻底消除对 platformUrl 的依赖, 版本兼容问题从根本上消失 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21 行
700 B
Kotlin
21 行
700 B
Kotlin
package com.xuqm.sdk.bugcollect
|
|
|
|
import android.content.Context
|
|
import com.xuqm.sdk.bugcollect.internal.LogStorage
|
|
|
|
internal object CrashCapture {
|
|
|
|
@Volatile private var started = false
|
|
|
|
/** 注册全局崩溃拦截器,只需 appContext + appKey,不依赖上传 URL。 */
|
|
fun start(appContext: Context, appKey: String, getUserId: () -> String?) {
|
|
if (started) return
|
|
started = true
|
|
val prev = Thread.getDefaultUncaughtExceptionHandler()
|
|
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
|
LogStorage.saveCrash(appContext, throwable, appKey, getUserId())
|
|
prev?.uncaughtException(thread, throwable)
|
|
}
|
|
}
|
|
}
|