From 3f03f5c1de5005e01bc0f253ed6e6e883d66a0b3 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Thu, 18 Jun 2026 19:29:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(bugcollect):=20=E5=B9=B3=E5=8F=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=8B=E5=8F=91=E5=90=8E=E5=BB=B6=E8=BF=9F=E9=87=8D?= =?UTF-8?q?=E8=AF=95=20flush=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - startCrashCapture 后延迟检查 bugCollectApiUrl,就绪后再次 flush - 添加调试日志帮助排查上传流程 --- .../com/xuqm/sdk/bugcollect/BugCollect.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sdk-bugcollect/src/main/java/com/xuqm/sdk/bugcollect/BugCollect.kt b/sdk-bugcollect/src/main/java/com/xuqm/sdk/bugcollect/BugCollect.kt index 34747b8..811b3e3 100644 --- a/sdk-bugcollect/src/main/java/com/xuqm/sdk/bugcollect/BugCollect.kt +++ b/sdk-bugcollect/src/main/java/com/xuqm/sdk/bugcollect/BugCollect.kt @@ -5,6 +5,12 @@ import android.content.Context import android.content.pm.ApplicationInfo import android.os.Build import com.xuqm.sdk.XuqmSDK +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import java.util.LinkedList object BugCollect { @@ -82,10 +88,12 @@ object BugCollect { ) if (!isReady()) { synchronized(pendingErrorsLock) { pendingErrors.add(event) } + android.util.Log.d("BugCollect", "captureError: SDK not ready, queued (${pendingErrors.size} pending)") return } flushPendingErrors() queue().push(event) + android.util.Log.d("BugCollect", "captureError: pushed to queue") } fun captureCrash(error: Throwable, tags: Map = emptyMap()) { @@ -153,6 +161,17 @@ object BugCollect { ) flushPendingErrors() queue().uploadPendingCrashes() + // 平台配置可能在初始化之后才下发,延迟重试 flush + GlobalScope.launch(Dispatchers.IO) { + for (i in 1..10) { + delay(2000) + if (!XuqmSDK.bugCollectApiUrl.isNullOrBlank()) { + flushPendingErrors() + queue().uploadPendingCrashes() + break + } + } + } } /** 将 SDK 未就绪时暂存的错误事件 flush 到队列。 */ @@ -163,6 +182,7 @@ object BugCollect { pendingErrors.clear() list } + android.util.Log.d("BugCollect", "flushPendingErrors: ${events.size} events") events.forEach { queue().push(it) } }