fix(sdk): 完善初始化异常处理和日志记录

- 在 XuqmInitializerProvider 中添加 autoInitialize 失败时的错误日志记录
- 在 autoInitialize 方法中添加许可证文件缺失时的详细错误日志
- 添加包名匹配失败时的错误日志记录
- 添加许可证读取成功时的调试日志
- 新增 listAssets 辅助方法用于列出资产目录文件
这个提交包含在:
XuqmGroup 2026-05-29 17:00:04 +08:00
父节点 e958b2a42c
当前提交 42b644ac11
共有 2 个文件被更改,包括 32 次插入2 次删除

查看文件

@ -44,16 +44,36 @@ object XuqmSDK {
*/
fun autoInitialize(context: Context, logLevel: LogLevel = LogLevel.WARN) {
val licenseData = readLicenseFileData(context)
?: throw IllegalStateException(
if (licenseData == null) {
android.util.Log.e(
"XuqmSDK",
"[autoInitialize] License file not found or unreadable. " +
"Expected assets/xuqm/license.xuqm or assets/xuqm/*.xuqmlicense. " +
"Actual files in assets/xuqm/: ${listAssets(context, "xuqm")}",
)
throw IllegalStateException(
"No license file found in assets/xuqm/. " +
"Download license.xuqm from the tenant platform and place it in src/main/assets/xuqm/."
)
}
val appKey = licenseData.first
val serverUrl = licenseData.second
val licensePackageName = licenseData.third
val localPackageName = context.packageName
android.util.Log.d(
"XuqmSDK",
"[autoInitialize] License read OK — " +
"appKey=${appKey.take(8)}***, serverUrl=$serverUrl, " +
"licensePackageName=$licensePackageName, localPackageName=$localPackageName",
)
if (licensePackageName != null && licensePackageName.isNotBlank() && licensePackageName != localPackageName) {
android.util.Log.e(
"XuqmSDK",
"[autoInitialize] Package name mismatch — " +
"license expects '$licensePackageName', app running as '$localPackageName'.",
)
throw IllegalStateException(
"License package name mismatch: license=$licensePackageName, local=$localPackageName. " +
"Please download the correct license file for this app."
@ -63,6 +83,9 @@ object XuqmSDK {
initialize(context, appKey, serverUrl, logLevel)
}
private fun listAssets(context: Context, dir: String): String =
runCatching { context.assets.list(dir)?.toList().toString() }.getOrDefault("(error listing)")
/**
* Manual initialization without license file.
* The SDK will validate the appKey against the server by calling /api/sdk/config

查看文件

@ -18,6 +18,13 @@ class XuqmInitializerProvider : ContentProvider() {
if (!XuqmSDK.isInitialized()) {
XuqmSDK.autoInitialize(ctx)
}
}.onFailure { e ->
android.util.Log.e(
"XuqmSDK",
"[XuqmInitializerProvider] autoInitialize failed — SDK will be uninitialized. " +
"Cause: ${e.javaClass.simpleName}: ${e.message}",
e,
)
}
return true
}