优化内容: - 新增 XuqmMergedProvider:合并 3 个 Provider 为 1 个,主线程只读文件字节 - 新增 ConfigCache:EncryptedSharedPreferences 持久化缓存解密结果 - ConfigFileReader 新增 readRawBytes() / readWithCache(),单例内存缓存 - XuqmSDK 新增 autoInitializeFromBytes():IO 线程完成解密+初始化 - BugCollectInitProvider 改为兼容 fallback,检查 isInitialized() 跳过 - XuqmInitializerProvider 标记 @Deprecated 性能对比: 优化前:主线程 ~350ms(PBKDF2 + 文件扫描 + 3 个 Provider 实例化) 优化后:主线程 ~7ms(文件发现 + 读字节),后续启动 ~3ms(读缓存) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| src/main | ||
| build.gradle.kts | ||
| consumer-rules.pro | ||
| README.md | ||
sdk-core
XuqmGroup Android SDK 核心模块。提供 SDK 初始化、HTTP 请求、Token 管理、文件操作、通用工具。
依赖
implementation("com.xuqm:sdk-core:VERSION")
初始化
方式 A — ContentProvider 自动初始化(推荐)
将 config.xuqm 放入 src/main/assets/xuqm/,SDK 在 App 启动时自动读取并初始化。
// XuqmInitializerProvider 自动触发,无需代码
方式 B — 手动初始化
// Application.onCreate() 中:
XuqmSDK.initialize(context, appKey = "xxx")
XuqmSDK.initialize(context, appKey = "xxx", platformUrl = "https://xxx")
API
XuqmSDK(全局单例)
| API | 说明 |
|---|---|
XuqmSDK.initialize(context, appKey, platformUrl?, logLevel?) |
手动初始化 |
XuqmSDK.awaitInitialization() |
等待平台配置拉取(coroutine) |
XuqmSDK.isInitialized() |
检查是否已初始化 |
XuqmSDK.setUserInfo(info) |
设置用户信息,触发所有子模块登录 |
XuqmSDK.setUserInfo(null) |
登出,触发全局登出 |
XuqmSDK.getUserId() |
获取当前 userId |
XuqmSDK.getUserInfo() |
获取当前用户信息 |
XuqmSDK.appKey |
当前 appKey |
XuqmSDK.platformConfig |
平台配置(init 后可用) |
XuqmSDK.bugCollectApiUrl |
Bug 收集服务地址(从平台配置获取) |
XuqmSDK.bugCollectEnabled |
是否启用 Bug 收集上报 |
XuqmSDK.useLocalServiceEndpoints(ip) |
切换本地联调环境 |
XuqmSDK.tokenStore |
Token 存储(EncryptedSharedPreferences) |
XuqmUserInfo
data class XuqmUserInfo(
val userId: String, // 必填
val userSig: String? = null, // IM 登录凭证(可选)
val name: String? = null,
val phone: String? = null,
val avatar: String? = null,
)
TokenStore
基于 EncryptedSharedPreferences 持久化存储。
XuqmSDK.tokenStore.saveToken("eyJ...")
val token = XuqmSDK.tokenStore.getToken()
XuqmSDK.tokenStore.clear()
ApiClient
基于 OkHttp 5 + Retrofit 3,自动附加 Bearer Token。
val service = RetrofitFactory.create(MyApiService::class.java)
FileSDK
文件上传、下载、打开的统一入口(com.xuqm.sdk.file)。
// 上传
val result = FileSDK.upload(context, uri, onProgress = { /* 0-100 */ })
val result = FileSDK.uploadBytes(fileName, mimeType, bytes, onProgress)
// 下载
val file = FileSDK.download(context, url, fileName, destination, notificationTitle, onProgress)
// 打开
FileSDK.openFile(context, file)