diff --git a/android/app/build.gradle b/android/app/build.gradle index b18d3067..a4f6f490 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,8 +1,29 @@ apply plugin: 'com.android.application' -def packageJson = new groovy.json.JsonSlurper().parseText(file('../../package.json').text) -def semver = packageJson.version.split('\\.') -def computedVersionCode = semver[0].toInteger() * 1000000 + semver[1].toInteger() * 1000 + semver[2].toInteger() +// Mirror of resolveAppVersion() in ../../vite.config.js so the APK's +// versionName matches __APP_VERSION__ rendered in the About screen. +// `git describe --tags --match 'v*'` against tag v0.2.0 yields +// `v0.2.0--g`; patch = commit count since the tag. +// Falls back to package.json only when git is unavailable. +def gitDescribe = providers.exec { + it.commandLine 'git', 'describe', '--tags', '--match', 'v*', '--always' + it.workingDir rootDir.parentFile + it.ignoreExitValue = true +} +def appVersion = { + def fromGit = gitDescribe.result.get().exitValue == 0 ? gitDescribe.standardOutput.asText.get().trim() : null + def m = fromGit =~ /^v?(\d+)\.(\d+)\.(\d+)(?:-(\d+)-g[0-9a-f]+)?$/ + if (fromGit && m.matches()) { + def major = m[0][1].toInteger() + def minor = m[0][2].toInteger() + def patch = (m[0][4] ?: m[0][3]).toInteger() + return [name: "${major}.${minor}.${patch}", major: major, minor: minor, patch: patch] + } + def pkg = new groovy.json.JsonSlurper().parseText(file('../../package.json').text) + def parts = pkg.version.split('\\.') + return [name: pkg.version, major: parts[0].toInteger(), minor: parts[1].toInteger(), patch: parts[2].toInteger()] +}() +def computedVersionCode = appVersion.major * 1000000 + appVersion.minor * 1000 + appVersion.patch android { namespace = "chat.vojo.app" @@ -12,7 +33,7 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode computedVersionCode - versionName packageJson.version + versionName appVersion.name 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/docs/ai/android.md b/docs/ai/android.md index e3482a90..072c9b88 100644 --- a/docs/ai/android.md +++ b/docs/ai/android.md @@ -26,7 +26,7 @@ npm run android:apk:debug # gradle debug build only ## Versioning -`versionCode` and `versionName` auto-derived from `package.json` version: +`versionCode` and `versionName` are derived from `git describe --tags --match 'v*'` in [`android/app/build.gradle`](../../android/app/build.gradle), mirroring `resolveAppVersion()` in [`vite.config.js`](../../vite.config.js) so the APK's `versionName` matches `__APP_VERSION__` shown in About. Tag is `v0.2.0`; `patch` is the commit count since that tag (e.g. `v0.2.0-87-g…` → versionName `0.2.87`). When git is unavailable, falls back to `package.json` `version`. ``` versionCode = major * 1_000_000 + minor * 1_000 + patch diff --git a/package.json b/package.json index f7873a56..59ab8424 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vojo", - "version": "4.11.1", - "description": "Yet another matrix client", + "version": "0.2.0", + "description": "Vojo client for matrix server", "main": "index.js", "type": "module", "engines": {