From f63054e937d1a83e981817ebf148b6ea8c58dfd1 Mon Sep 17 00:00:00 2001 From: KKRainbow <443152178@qq.com> Date: Sun, 19 Apr 2026 19:06:37 +0800 Subject: [PATCH] fix: resolve Android APK version fallback to 1.0 on CI (#2131) --- .../gen/android/app/build.gradle.kts | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/easytier-gui/src-tauri/gen/android/app/build.gradle.kts b/easytier-gui/src-tauri/gen/android/app/build.gradle.kts index f55d32de..c160d076 100644 --- a/easytier-gui/src-tauri/gen/android/app/build.gradle.kts +++ b/easytier-gui/src-tauri/gen/android/app/build.gradle.kts @@ -1,5 +1,6 @@ import java.util.Properties import java.io.FileInputStream +import groovy.json.JsonSlurper plugins { id("com.android.application") @@ -14,6 +15,35 @@ val tauriProperties = Properties().apply { } } +val versionPattern = Regex("""^(\d+)\.(\d+)\.(\d+)$""") + +val tauriVersionName = tauriProperties.getProperty("tauri.android.versionName")?.ifBlank { null } ?: run { + val tauriConfFile = file("../../../tauri.conf.json") + check(tauriConfFile.exists()) { "Missing tauri.conf.json at ${tauriConfFile.path}" } + + val tauriConf = tauriConfFile.reader(Charsets.UTF_8).use { JsonSlurper().parse(it) as? Map<*, *> } + ?: error("Failed to parse ${tauriConfFile.path} as a JSON object") + tauriConf["version"] as? String + ?: error("Missing string field \"version\" in ${tauriConfFile.path}") +} + +val tauriVersionMatch = versionPattern.matchEntire(tauriVersionName) + ?: error("Android version must use x.y.z format, but got \"$tauriVersionName\"") + +val tauriVersionCode = if (tauriProperties.getProperty("tauri.android.versionName")?.ifBlank { null } != null) { + val versionCodeProp = tauriProperties.getProperty("tauri.android.versionCode") + if (versionCodeProp != null) { + versionCodeProp.toIntOrNull() + ?: error("Property \"tauri.android.versionCode\" must be an integer, but got \"$versionCodeProp\"") + } else { + val (major, minor, patch) = tauriVersionMatch.destructured + major.toInt() * 1_000_000 + minor.toInt() * 1_000 + patch.toInt() + } +} else { + val (major, minor, patch) = tauriVersionMatch.destructured + major.toInt() * 1_000_000 + minor.toInt() * 1_000 + patch.toInt() +} + android { compileSdk = 34 namespace = "com.kkrainbow.easytier" @@ -22,8 +52,8 @@ android { applicationId = "com.kkrainbow.easytier" minSdk = 24 targetSdk = 34 - versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt() - versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0") + versionCode = tauriVersionCode + versionName = tauriVersionName } signingConfigs { create("release") { @@ -82,4 +112,4 @@ dependencies { androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0") } -apply(from = "tauri.build.gradle.kts") \ No newline at end of file +apply(from = "tauri.build.gradle.kts")