Skip to content

Commit aca5005

Browse files
committed
fix(android): give Wear releases unique version codes
1 parent a4b8ae9 commit aca5005

5 files changed

Lines changed: 51 additions & 5 deletions

File tree

‎apps/android/Config/Version.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
OPENCLAW_ANDROID_VERSION_NAME=2026.7.2
66
OPENCLAW_ANDROID_VERSION_CODE=2026070201
7+
OPENCLAW_ANDROID_WEAR_VERSION_CODE=260702011

‎apps/android/VERSIONING.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ Android release builds use pinned app metadata instead of auto-bumping `build.gr
66

77
- `apps/android/version.json` is the source of truth.
88
- `version` is the Play `versionName` and uses CalVer: `YYYY.M.D`.
9-
- `versionCode` uses `YYYYMMDDNN`, where `NN` is a two-digit build number for that pinned app version.
9+
- the phone `versionCode` uses `YYYYMMDDNN`, where `NN` is a two-digit build number for that pinned app version.
10+
- the generated Wear `versionCode` uses the independent `YYMMDDNN1` range. The final `1` identifies the Wear
11+
form factor, so phone and watch artifacts never reuse a Play version code.
1012
- `apps/android/Config/Version.properties` is generated from `version.json` and read by Gradle.
1113
- `apps/android/CHANGELOG.md` is the Android-only changelog and release-note source.
1214
- `apps/android/fastlane/metadata/android/en-US/release_notes.txt` is generated from the changelog.
1315

1416
Examples:
1517

1618
- `version = 2026.6.2`
17-
- `versionCode = 2026060201`
18-
- another upload on the same release train: `versionCode = 2026060202`
19+
- phone `versionCode = 2026060201`
20+
- Wear `versionCode = 260602011`
21+
- another upload on the same release train: phone `2026060202`, Wear `260602021`
22+
23+
The separate Wear range follows the
24+
[Wear OS packaging requirement](https://developer.android.com/training/wearables/packaging#version-code)
25+
that watch artifacts use version codes unique across form factors.
1926

2027
## Commands
2128

‎apps/android/wear/build.gradle.kts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ fun requireOpenClawAndroidVersionProperty(name: String): String =
1313
openClawAndroidVersionProperties.getProperty(name)?.trim()?.takeIf { it.isNotEmpty() }
1414
?: error("Missing $name in Config/Version.properties. Run `pnpm android:version:sync`.")
1515

16+
val openClawAndroidWearVersionCode =
17+
requireOpenClawAndroidVersionProperty("OPENCLAW_ANDROID_WEAR_VERSION_CODE").toIntOrNull()
18+
?: error("OPENCLAW_ANDROID_WEAR_VERSION_CODE must be an integer in Config/Version.properties.")
19+
1620
plugins {
1721
alias(libs.plugins.android.application)
1822
alias(libs.plugins.ktlint)
@@ -29,7 +33,7 @@ android {
2933
applicationId = "ai.openclaw.app"
3034
minSdk = 31
3135
targetSdk = 36
32-
versionCode = requireOpenClawAndroidVersionProperty("OPENCLAW_ANDROID_VERSION_CODE").toInt()
36+
versionCode = openClawAndroidWearVersionCode
3337
versionName = requireOpenClawAndroidVersionProperty("OPENCLAW_ANDROID_VERSION_NAME")
3438
}
3539

‎scripts/lib/android-version.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ANDROID_CHANGELOG_FILE = "apps/android/CHANGELOG.md";
88
const ANDROID_VERSION_PROPERTIES_FILE = "apps/android/Config/Version.properties";
99
const ANDROID_RELEASE_NOTES_FILE = "apps/android/fastlane/metadata/android/en-US/release_notes.txt";
1010
const ANDROID_VERSION_CODE_MAX = 2_100_000_000;
11+
const ANDROID_WEAR_VERSION_CODE_SUFFIX = "1";
1112

1213
type AndroidVersionManifest = {
1314
version: string;
@@ -114,6 +115,26 @@ export function normalizeAndroidVersionCode(rawVersionCode: number, version: str
114115
return rawVersionCode;
115116
}
116117

118+
export function canonicalAndroidWearVersionCode(
119+
rawVersionCode: number,
120+
version: string,
121+
): number {
122+
const phoneVersionCode = normalizeAndroidVersionCode(rawVersionCode, version).toString();
123+
const wearVersionCode = Number(
124+
`${phoneVersionCode.slice(2)}${ANDROID_WEAR_VERSION_CODE_SUFFIX}`,
125+
);
126+
if (
127+
!Number.isSafeInteger(wearVersionCode) ||
128+
wearVersionCode <= 0 ||
129+
wearVersionCode > ANDROID_VERSION_CODE_MAX
130+
) {
131+
throw new Error(
132+
`Unable to derive Wear versionCode from Android versionCode ${rawVersionCode}.`,
133+
);
134+
}
135+
return wearVersionCode;
136+
}
137+
117138
function readRootPackageVersion(rootDir = path.resolve(".")): string {
118139
const packageJsonPath = path.join(rootDir, "package.json");
119140
const parsed = JSON.parse(readFileSync(packageJsonPath, "utf8")) as { version?: unknown };
@@ -185,7 +206,11 @@ export function resolveAndroidVersion(rootDir = path.resolve(".")): ResolvedAndr
185206
export function renderAndroidVersionProperties(
186207
version: Pick<ResolvedAndroidVersion, "canonicalVersion" | "versionCode">,
187208
): string {
188-
return `# Shared Android version defaults.\n# Source of truth: apps/android/version.json\n# Generated by scripts/android-sync-versioning.ts.\n\nOPENCLAW_ANDROID_VERSION_NAME=${version.canonicalVersion}\nOPENCLAW_ANDROID_VERSION_CODE=${version.versionCode}\n`;
209+
const wearVersionCode = canonicalAndroidWearVersionCode(
210+
version.versionCode,
211+
version.canonicalVersion,
212+
);
213+
return `# Shared Android version defaults.\n# Source of truth: apps/android/version.json\n# Generated by scripts/android-sync-versioning.ts.\n\nOPENCLAW_ANDROID_VERSION_NAME=${version.canonicalVersion}\nOPENCLAW_ANDROID_VERSION_CODE=${version.versionCode}\nOPENCLAW_ANDROID_WEAR_VERSION_CODE=${wearVersionCode}\n`;
189214
}
190215

191216
function matchChangelogHeading(line: string, heading: string): boolean {

‎test/scripts/android-version.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { spawnSync } from "node:child_process";
33
import path from "node:path";
44
import { describe, expect, it } from "vitest";
55
import {
6+
canonicalAndroidWearVersionCode,
67
canonicalAndroidVersionCode,
78
extractChangelogSection,
89
normalizeGatewayVersionToPinnedAndroidVersion,
@@ -176,6 +177,11 @@ describe("gateway version normalization", () => {
176177
expect(canonicalAndroidVersionCode("2026.6.2")).toBe(2026060201);
177178
});
178179

180+
it("derives a dedicated Play-compatible Wear versionCode range", () => {
181+
expect(canonicalAndroidWearVersionCode(2026060201, "2026.6.2")).toBe(260602011);
182+
expect(canonicalAndroidWearVersionCode(2026060202, "2026.6.2")).toBe(260602021);
183+
});
184+
179185
it("rejects pinned versions that cannot derive Play-compatible version codes", () => {
180186
expect(() => canonicalAndroidVersionCode("2026.6.100")).toThrow(
181187
"Unable to derive Android versionCode from 2026.6.100",
@@ -220,6 +226,9 @@ describe("renderAndroidVersionProperties", () => {
220226
expect(renderAndroidVersionProperties(version)).toContain(
221227
"OPENCLAW_ANDROID_VERSION_CODE=2026060201",
222228
);
229+
expect(renderAndroidVersionProperties(version)).toContain(
230+
"OPENCLAW_ANDROID_WEAR_VERSION_CODE=260602011",
231+
);
223232
});
224233
});
225234

0 commit comments

Comments
 (0)