diff --git a/android/app/build.gradle b/android/app/build.gradle index 17ca780..3350a4b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,5 +1,15 @@ apply plugin: 'com.android.application' +// 从 package.json 读取版本号 +def packageJsonFile = file('../../package.json') +def packageJsonText = packageJsonFile.text +// 使用正则提取版本号 +def versionMatcher = packageJsonText =~ /"version"\s*:\s*"([^"]+)"/ +def appVersionName = versionMatcher ? versionMatcher[0][1] : "1.0.0" +// 将版本号转换为 versionCode,例如 "1.5.5" -> 1*10000 + 5*100 + 5 = 10505 +def versionParts = appVersionName.split('\\.') +def appVersionCode = versionParts[0].toInteger() * 10000 + versionParts[1].toInteger() * 100 + versionParts[2].toInteger() + android { namespace = "games.wenzi.ogame" compileSdk = rootProject.ext.compileSdkVersion @@ -7,8 +17,8 @@ android { applicationId "games.wenzi.ogame" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 15 - versionName "1.5.0" + versionCode appVersionCode + versionName appVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/package.json b/package.json index b1c1287..6c5381c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "private": true, "version": "1.5.5", - "buildDate": "2025/12/25 18:23:43", + "buildDate": "2025/12/26 01:02:13", "main": "dist-electron/main.js", "type": "module", "scripts": {