mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(android): skip gradle resource tasks on linux arm
This commit is contained in:
18
package.json
18
package.json
@@ -1417,19 +1417,19 @@
|
|||||||
"./cli-entry": "./openclaw.mjs"
|
"./cli-entry": "./openclaw.mjs"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"android:assemble": "cd apps/android && ./gradlew :app:assemblePlayDebug",
|
"android:assemble": "node scripts/run-android-gradle.mjs :app:assemblePlayDebug",
|
||||||
"android:assemble:third-party": "cd apps/android && ./gradlew :app:assembleThirdPartyDebug",
|
"android:assemble:third-party": "node scripts/run-android-gradle.mjs :app:assembleThirdPartyDebug",
|
||||||
"android:bundle:release": "bun apps/android/scripts/build-release-aab.ts",
|
"android:bundle:release": "bun apps/android/scripts/build-release-aab.ts",
|
||||||
"android:format": "cd apps/android && ./gradlew :app:ktlintFormat :benchmark:ktlintFormat",
|
"android:format": "cd apps/android && ./gradlew :app:ktlintFormat :benchmark:ktlintFormat",
|
||||||
"android:install": "cd apps/android && ./gradlew :app:installPlayDebug",
|
"android:install": "node scripts/run-android-gradle.mjs :app:installPlayDebug",
|
||||||
"android:install:third-party": "cd apps/android && ./gradlew :app:installThirdPartyDebug",
|
"android:install:third-party": "node scripts/run-android-gradle.mjs :app:installThirdPartyDebug",
|
||||||
"android:lint": "cd apps/android && ./gradlew :app:ktlintCheck :benchmark:ktlintCheck",
|
"android:lint": "cd apps/android && ./gradlew :app:ktlintCheck :benchmark:ktlintCheck",
|
||||||
"android:lint:android": "cd apps/android && ./gradlew :app:lintDebug",
|
"android:lint:android": "node scripts/run-android-gradle.mjs :app:lintDebug",
|
||||||
"android:run": "cd apps/android && ./gradlew :app:installPlayDebug && adb shell am start -n ai.openclaw.app/.MainActivity",
|
"android:run": "node scripts/run-android-gradle.mjs :app:installPlayDebug -- adb shell am start -n ai.openclaw.app/.MainActivity",
|
||||||
"android:run:third-party": "cd apps/android && ./gradlew :app:installThirdPartyDebug && adb shell am start -n ai.openclaw.app/.MainActivity",
|
"android:run:third-party": "node scripts/run-android-gradle.mjs :app:installThirdPartyDebug -- adb shell am start -n ai.openclaw.app/.MainActivity",
|
||||||
"android:test": "cd apps/android && ./gradlew :app:testPlayDebugUnitTest",
|
"android:test": "node scripts/run-android-gradle.mjs :app:testPlayDebugUnitTest",
|
||||||
"android:test:integration": "node scripts/run-with-env.mjs OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_ANDROID_NODE=1 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.live.config.ts src/gateway/android-node.capabilities.live.test.ts",
|
"android:test:integration": "node scripts/run-with-env.mjs OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_ANDROID_NODE=1 -- node scripts/run-vitest.mjs run --config test/vitest/vitest.live.config.ts src/gateway/android-node.capabilities.live.test.ts",
|
||||||
"android:test:third-party": "cd apps/android && ./gradlew :app:testThirdPartyDebugUnitTest",
|
"android:test:third-party": "node scripts/run-android-gradle.mjs :app:testThirdPartyDebugUnitTest",
|
||||||
"audit:seams": "node scripts/audit-seams.mjs",
|
"audit:seams": "node scripts/audit-seams.mjs",
|
||||||
"build": "node scripts/build-all.mjs",
|
"build": "node scripts/build-all.mjs",
|
||||||
"build:ci-artifacts": "node scripts/build-all.mjs ciArtifacts",
|
"build:ci-artifacts": "node scripts/build-all.mjs ciArtifacts",
|
||||||
|
|||||||
91
scripts/run-android-gradle.mjs
Normal file
91
scripts/run-android-gradle.mjs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { spawn } from "node:child_process";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const repoRoot = path.resolve(scriptDir, "..");
|
||||||
|
const androidDir = path.join(repoRoot, "apps", "android");
|
||||||
|
const isMain = process.argv[1]
|
||||||
|
? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
||||||
|
: false;
|
||||||
|
|
||||||
|
export function splitAndroidGradleArgs(argv) {
|
||||||
|
const separator = argv.indexOf("--");
|
||||||
|
if (separator === -1) {
|
||||||
|
return { gradleArgs: argv, postArgs: [] };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
gradleArgs: argv.slice(0, separator),
|
||||||
|
postArgs: argv.slice(separator + 1),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shouldSkipLinuxArmAndroidGradle(options = {}) {
|
||||||
|
const platform = options.platform ?? process.platform;
|
||||||
|
const arch = options.arch ?? process.arch;
|
||||||
|
const env = options.env ?? process.env;
|
||||||
|
if (env.OPENCLAW_ANDROID_GRADLE_ALLOW_LINUX_ARM === "1") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return platform === "linux" && (arch === "arm64" || arch === "arm");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function linuxArmAndroidGradleSkipMessage(platform = process.platform, arch = process.arch) {
|
||||||
|
return (
|
||||||
|
`[android-gradle] skipped on ${platform}/${arch}: ` +
|
||||||
|
"Android Gradle resource tasks require the Linux x86_64 AAPT2 artifact. " +
|
||||||
|
"Run this task on x64 Linux/macOS or set OPENCLAW_ANDROID_GRADLE_ALLOW_LINUX_ARM=1 to try anyway."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function run(command, args, cwd) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const child = spawn(command, args, {
|
||||||
|
cwd,
|
||||||
|
env: process.env,
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
child.on("close", (status, signal) => {
|
||||||
|
if (typeof status === "number") {
|
||||||
|
resolve(status);
|
||||||
|
} else if (signal) {
|
||||||
|
resolve(128);
|
||||||
|
} else {
|
||||||
|
resolve(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
child.on("error", (error) => {
|
||||||
|
console.error(error instanceof Error ? error.message : String(error));
|
||||||
|
resolve(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function main(argv = process.argv.slice(2)) {
|
||||||
|
const { gradleArgs, postArgs } = splitAndroidGradleArgs(argv);
|
||||||
|
if (gradleArgs.length === 0) {
|
||||||
|
console.error(
|
||||||
|
"Usage: node scripts/run-android-gradle.mjs <gradle-task...> [-- <post-command...>]",
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldSkipLinuxArmAndroidGradle()) {
|
||||||
|
// Google's Linux AAPT2 artifact is x86_64-only, so resource tasks fail on
|
||||||
|
// Linux arm64 before app code or tests run. CI Android lanes use x64 runners.
|
||||||
|
console.log(linuxArmAndroidGradleSkipMessage());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gradleStatus = await run("./gradlew", gradleArgs, androidDir);
|
||||||
|
if (gradleStatus !== 0 || postArgs.length === 0) {
|
||||||
|
return gradleStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await run(postArgs[0], postArgs.slice(1), repoRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMain) {
|
||||||
|
process.exit(await main());
|
||||||
|
}
|
||||||
40
test/scripts/run-android-gradle.test.ts
Normal file
40
test/scripts/run-android-gradle.test.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import {
|
||||||
|
linuxArmAndroidGradleSkipMessage,
|
||||||
|
shouldSkipLinuxArmAndroidGradle,
|
||||||
|
splitAndroidGradleArgs,
|
||||||
|
} from "../../scripts/run-android-gradle.mjs";
|
||||||
|
|
||||||
|
describe("run-android-gradle", () => {
|
||||||
|
it("splits Gradle args from an optional post command", () => {
|
||||||
|
expect(
|
||||||
|
splitAndroidGradleArgs([":app:installPlayDebug", "--", "adb", "shell", "am", "start"]),
|
||||||
|
).toEqual({
|
||||||
|
gradleArgs: [":app:installPlayDebug"],
|
||||||
|
postArgs: ["adb", "shell", "am", "start"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("skips Linux ARM hosts by default because AAPT2 is x86_64-only", () => {
|
||||||
|
expect(shouldSkipLinuxArmAndroidGradle({ arch: "arm64", platform: "linux" })).toBe(true);
|
||||||
|
expect(shouldSkipLinuxArmAndroidGradle({ arch: "arm", platform: "linux" })).toBe(true);
|
||||||
|
expect(shouldSkipLinuxArmAndroidGradle({ arch: "x64", platform: "linux" })).toBe(false);
|
||||||
|
expect(shouldSkipLinuxArmAndroidGradle({ arch: "arm64", platform: "darwin" })).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows an explicit Linux ARM override", () => {
|
||||||
|
expect(
|
||||||
|
shouldSkipLinuxArmAndroidGradle({
|
||||||
|
arch: "arm64",
|
||||||
|
env: { OPENCLAW_ANDROID_GRADLE_ALLOW_LINUX_ARM: "1" },
|
||||||
|
platform: "linux",
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("explains the skip with the override escape hatch", () => {
|
||||||
|
expect(linuxArmAndroidGradleSkipMessage("linux", "arm64")).toContain(
|
||||||
|
"OPENCLAW_ANDROID_GRADLE_ALLOW_LINUX_ARM=1",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user