fix: auto-init XuqmSDK via ContentProvider; remove packageName from update check; fix Jenkinsfile
- sdk-core: add XuqmInitializerProvider for auto-init at app startup - sdk-core: register provider in AndroidManifest.xml - sdk-license: remove duplicate XuqmSDK init from LicenseInitializerProvider - sdk-update: awaitInitialization() now uses requireInit() directly (no 30s polling) - Jenkinsfile: replace Windows external commands (findstr/powershell) with Groovy readFile/writeFile Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
这个提交包含在:
父节点
87ef2bf104
当前提交
db3ec3d377
15
Jenkinsfile
vendored
15
Jenkinsfile
vendored
@ -50,12 +50,10 @@ pipeline {
|
||||
stage('Resolve Versions') {
|
||||
steps {
|
||||
script {
|
||||
// Read version using cmd.exe findstr
|
||||
def verRaw = bat(
|
||||
script: '@findstr /B "PUBLISH_VERSION=" gradle.properties',
|
||||
returnStdout: true
|
||||
).trim()
|
||||
def currentVer = verRaw.contains('=') ? verRaw.split('=', 2)[1].trim() : '0.1.0'
|
||||
// Read version using pure Groovy (no Windows external commands)
|
||||
def props = readFile('gradle.properties')
|
||||
def verLine = props.readLines().find { it.trim().startsWith('PUBLISH_VERSION=') }
|
||||
def currentVer = verLine ? verLine.split('=', 2)[1].trim() : '0.1.0'
|
||||
echo "Current PUBLISH_VERSION: ${currentVer}"
|
||||
|
||||
def parts = currentVer.tokenize('.')
|
||||
@ -72,8 +70,9 @@ pipeline {
|
||||
echo "Auto-bumped PUBLISH_VERSION: ${currentVer} → ${newVer}"
|
||||
env.NEW_VERSION = newVer
|
||||
|
||||
// Write back using powershell
|
||||
bat "powershell -Command \"(Get-Content gradle.properties) -replace '^PUBLISH_VERSION=.*', 'PUBLISH_VERSION=${newVer}' | Set-Content -NoNewline gradle.properties\""
|
||||
// Write back using pure Groovy
|
||||
def newProps = props.replaceAll(/(?m)^PUBLISH_VERSION=.*/, "PUBLISH_VERSION=${newVer}")
|
||||
writeFile(file: 'gradle.properties', text: newProps)
|
||||
|
||||
def modules = env.PUBLISH_MODULES.split(',').toList()
|
||||
def versionMap = [:]
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application>
|
||||
<provider
|
||||
android:name="com.xuqm.sdk.internal.XuqmInitializerProvider"
|
||||
android:authorities="${applicationId}.xuqm-init"
|
||||
android:exported="false"
|
||||
android:initOrder="90" />
|
||||
</application>
|
||||
</manifest>
|
||||
@ -0,0 +1,30 @@
|
||||
package com.xuqm.sdk.internal
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import com.xuqm.sdk.XuqmSDK
|
||||
|
||||
/**
|
||||
* Auto-initializes XuqmSDK at app startup when a license file is present.
|
||||
* Registered in sdk-core AndroidManifest so any module (im/update/push/license)
|
||||
* triggers one-shot initialization without explicit init calls from the app.
|
||||
*/
|
||||
class XuqmInitializerProvider : ContentProvider() {
|
||||
override fun onCreate(): Boolean {
|
||||
val ctx = context?.applicationContext ?: return true
|
||||
runCatching {
|
||||
if (!XuqmSDK.isInitialized()) {
|
||||
XuqmSDK.autoInitialize(ctx)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
||||
override fun getType(uri: Uri): String? = null
|
||||
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
}
|
||||
@ -10,14 +10,8 @@ class LicenseInitializerProvider : ContentProvider() {
|
||||
override fun onCreate(): Boolean {
|
||||
val ctx = context ?: return true
|
||||
LicenseContextHolder.init(ctx)
|
||||
// Auto-initialize the full SDK if a license file is present in assets/xuqm/.
|
||||
// Runs before Application.onCreate(), so no app-level init code is needed.
|
||||
runCatching {
|
||||
val licenseFile = LicenseFileReader.read(ctx) ?: return@runCatching
|
||||
val appKey = licenseFile.appKey.takeIf { it.isNotBlank() } ?: return@runCatching
|
||||
val serverUrl = licenseFile.serverUrl?.takeIf { it.isNotBlank() }
|
||||
XuqmSDK.initialize(ctx, appKey, serverUrl)
|
||||
}
|
||||
// SDK initialization is handled by sdk-core XuqmInitializerProvider.
|
||||
// This provider only ensures LicenseContextHolder has the application context.
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@ -49,19 +49,7 @@ object UpdateSDK {
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
private suspend fun awaitInitialization() {
|
||||
val xuqmClazz = runCatching { Class.forName("com.xuqm.sdk.XuqmSDK") }.getOrNull()
|
||||
if (xuqmClazz != null) {
|
||||
val isInitMethod = xuqmClazz.getMethod("isInitialized")
|
||||
val maxWaitMs = 30000L
|
||||
val start = System.currentTimeMillis()
|
||||
while (!(isInitMethod.invoke(null) as Boolean)) {
|
||||
if (System.currentTimeMillis() - start > maxWaitMs) {
|
||||
throw IllegalStateException("UpdateSDK initialization timed out waiting for XuqmSDK")
|
||||
}
|
||||
kotlinx.coroutines.delay(100)
|
||||
}
|
||||
}
|
||||
private fun awaitInitialization() {
|
||||
XuqmSDK.requireInit()
|
||||
}
|
||||
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户