refactor(sdk): 移除初始化失败日志记录并优化错误处理
- 移除了 XuqmInitializerProvider 中的异常日志记录逻辑 - 将失败原因存储至 XuqmSDK.getInitError() 供应用决定展示方式 - 优化了授权文件不存在时的错误信息提示 - 简化了包名不匹配的错误处理流程 - 移除了调试日志输出以提升性能 - 改进了错误消息的中文本地化显示
这个提交包含在:
父节点
42b644ac11
当前提交
2404809649
@ -45,15 +45,10 @@ object XuqmSDK {
|
|||||||
fun autoInitialize(context: Context, logLevel: LogLevel = LogLevel.WARN) {
|
fun autoInitialize(context: Context, logLevel: LogLevel = LogLevel.WARN) {
|
||||||
val licenseData = readLicenseFileData(context)
|
val licenseData = readLicenseFileData(context)
|
||||||
if (licenseData == null) {
|
if (licenseData == null) {
|
||||||
android.util.Log.e(
|
val found = runCatching { context.assets.list("xuqm")?.toList() }.getOrDefault(emptyList())
|
||||||
"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(
|
throw IllegalStateException(
|
||||||
"No license file found in assets/xuqm/. " +
|
"授权文件未找到(assets/xuqm/ 下实际文件:$found)。" +
|
||||||
"Download license.xuqm from the tenant platform and place it in src/main/assets/xuqm/."
|
"请将 license.xuqm 放置到 src/<flavor>/assets/xuqm/ 目录。"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val appKey = licenseData.first
|
val appKey = licenseData.first
|
||||||
@ -61,31 +56,17 @@ object XuqmSDK {
|
|||||||
val licensePackageName = licenseData.third
|
val licensePackageName = licenseData.third
|
||||||
val localPackageName = context.packageName
|
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) {
|
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(
|
throw IllegalStateException(
|
||||||
"License package name mismatch: license=$licensePackageName, local=$localPackageName. " +
|
"授权文件与当前应用不匹配:" +
|
||||||
"Please download the correct license file for this app."
|
"授权包名 '$licensePackageName',当前包名 '$localPackageName'。" +
|
||||||
|
"请下载正确版本的授权文件。"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(context, appKey, serverUrl, logLevel)
|
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.
|
* Manual initialization without license file.
|
||||||
* The SDK will validate the appKey against the server by calling /api/sdk/config
|
* The SDK will validate the appKey against the server by calling /api/sdk/config
|
||||||
|
|||||||
@ -18,14 +18,8 @@ class XuqmInitializerProvider : ContentProvider() {
|
|||||||
if (!XuqmSDK.isInitialized()) {
|
if (!XuqmSDK.isInitialized()) {
|
||||||
XuqmSDK.autoInitialize(ctx)
|
XuqmSDK.autoInitialize(ctx)
|
||||||
}
|
}
|
||||||
}.onFailure { e ->
|
|
||||||
android.util.Log.e(
|
|
||||||
"XuqmSDK",
|
|
||||||
"[XuqmInitializerProvider] autoInitialize failed — SDK will be uninitialized. " +
|
|
||||||
"Cause: ${e.javaClass.simpleName}: ${e.message}",
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
// 失败原因已存入 XuqmSDK.getInitError(),由 App 决定如何展示
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户