XuqmGroup-AndroidSDK/sdk-bugcollect
XuqmGroup cc1557daf0 fix(bugcollect): 修复 fatal crash 不上报——startCrashCapture 从未被调用
根本原因链:
1. XuqmInitializerProvider 只调用 XuqmSDK.autoInitialize,从不调用 startCrashCapture
2. 即使调用,startCrashCapture 检查 bugCollectApiUrl == null 即提前返回;
   而 bugCollectApiUrl 由远端配置下发,崩溃发生时往往尚未到达
3. UncaughtExceptionHandler 从未注册,崩溃文件没有写入,下次启动无数据可上报

修复:
- XuqmSDK 新增 platformUrl 属性(同步可用,初始化即有值)
- BugCollect.startCrashCapture 不再依赖 bugCollectApiUrl,
  用 platformUrl + "/api/bugcollect/" 作为兜底 URL 写入崩溃文件
- LogQueue.uploadPendingCrashes 优先使用崩溃文件内保存的 logApiUrl
- XuqmInitializerProvider 通过反射调用 BugCollect.startCrashCapture,
  在 SDK 初始化后立即注册 UncaughtExceptionHandler

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 10:05:43 +08:00
..
src/main/java/com/xuqm/sdk/bugcollect fix(bugcollect): 修复 fatal crash 不上报——startCrashCapture 从未被调用 2026-06-18 10:05:43 +08:00
build.gradle.kts fix: bugcollect 模块 Java 11 → 17(Jenkins agent 无法下载 Java 11) 2026-06-17 18:39:34 +08:00
README.md refactor: sdk-log → sdk-bugcollect 2026-06-16 17:39:23 +08:00

sdk-bugcollect

XuqmGroup Android SDK Bug 采集模块。提供错误采集、Crash 捕获、漏斗分析能力。

依赖

implementation("com.xuqm:sdk-bugcollect:VERSION")
implementation("com.xuqm:sdk-core:VERSION")  // 必须

快速开始

// Application.onCreate() 中XuqmSDK.initialize 之后):
BugCollect.setLogLevel(LogLevel.INFO)
BugCollect.setEnvironment("production")
BugCollect.startCrashCapture()

// 业务代码中
BugCollect.event("page_view", mapOf("page" to "home"))
BugCollect.captureError(exception)

API

BugCollect 对象

API 说明
BugCollect.setLogLevel(level) 设置日志级别(DEBUG / INFO / WARN / ERROR
BugCollect.setEnvironment(env) 设置环境标签
BugCollect.startCrashCapture() 开启全局 UncaughtExceptionHandler
BugCollect.event(name, properties?) 记录自定义事件
BugCollect.captureError(error, metadata?) 上报异常
BugCollect.warn(message, metadata?) 记录警告
BugCollect.info(message, metadata?) 记录信息
BugCollect.defineFunnel(id, steps) 定义漏斗

LogLevel

enum class LogLevel { DEBUG, INFO, WARN, ERROR, NONE }

工作原理

  • LogQueue:事件进入内存队列,按批次异步上传到 bugCollectApiUrl
  • CrashCapture:注册 Thread.UncaughtExceptionHandler,捕获 Native Crash 并写入文件,下次启动时上传
  • Fingerprint:为错误生成指纹(基于 message + stack,服务端去重聚合
  • FunnelTracker:客户端维护漏斗进度,服务端跨 session 聚合

配置

bugCollectApiUrlbugCollectEnabledsdk-core 在 init 后从平台配置自动获取,无需 App 传入。