feat(sdk-core): ConfigFileReader 新增 assets/config/ 目录支持

对齐 RN SDK 的 src/assets/config/ 目录约定:
搜索顺序:config/config.xuqmconfig → config/*.xuqmconfig → xuqm/config.xuqm → xuqm/*.xuqmconfig
旧路径 assets/xuqm/ 保持兼容。

Co-Authored-By: Claude <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-06-18 15:06:40 +08:00
父节点 ba6de0a5fd
当前提交 75c1d77965

查看文件

@ -5,21 +5,24 @@ import android.util.Log
import com.google.gson.Gson
/**
* Reads and decrypts the init config file from assets/xuqm/.
* Looks for config.xuqm first, then falls back to any *.xuqmconfig file.
* This is used by XuqmSDK.autoInitialize() and does NOT depend on sdk-license.
* Reads and decrypts the init config file from assets.
*
* 搜索顺序对齐 RN SDK src/assets/config/
* 1. assets/config/config.xuqmconfig config.xuqm
* 2. assets/config/*.xuqmconfig取第一个
* 3. assets/xuqm/config.xuqm旧路径兼容
* 4. assets/xuqm/*.xuqmconfig旧路径兼容
*/
internal object ConfigFileReader {
private const val TAG = "XuqmSDK"
private const val CONFIG_PATH = "xuqm/config.xuqm"
private const val CONFIG_DIR = "xuqm"
private val CONFIG_DIRS = listOf("config", "xuqm")
private val gson = Gson()
fun read(context: Context): ConfigFile? {
return try {
val path = findConfigPath(context) ?: run {
Log.w(TAG, "No config file found in assets/$CONFIG_DIR/")
Log.w(TAG, "No config file found in assets/{config,xuqm}/")
return null
}
Log.d(TAG, "Reading config file: $path")
@ -39,16 +42,23 @@ internal object ConfigFileReader {
}
private fun findConfigPath(context: Context): String? {
try {
context.assets.open(CONFIG_PATH).close()
return CONFIG_PATH
} catch (_: Exception) {
// Try downloaded filenames such as appName.xuqmconfig.
for (dir in CONFIG_DIRS) {
// 优先 config.xuqmconfig 或 config.xuqm
for (name in listOf("config.xuqmconfig", "config.xuqm")) {
val path = "$dir/$name"
try {
context.assets.open(path).close()
return path
} catch (_: Exception) { /* not found */ }
}
// 否则取第一个 .xuqmconfig
val found = runCatching {
context.assets.list(dir)
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
?.let { "$dir/$it" }
}.getOrNull()
if (found != null) return found
}
return runCatching {
context.assets.list(CONFIG_DIR)
?.firstOrNull { it.endsWith(".xuqmconfig", ignoreCase = true) }
?.let { "$CONFIG_DIR/$it" }
}.getOrNull()
return null
}
}