@devries-cameron20 / t3code-1 / commits / 25c5032b3b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(devices): require a complete Android SDK on SSH hosts (#24566)

Julius Marminge committed Nov 13, 2026 at 23:27 UTC 25c5032b3b194c1a9601bbfa3e612a7516e650a7
3 files changed +118 -6
apps/server/src/device/sshDeviceScript.test.ts
+94 -2
@@ -11,6 +11,98 @@ import { quoteRemoteArg, remoteDeviceEnvironment, remoteDeviceScript } from "./s
11
12 const exec = NodeUtil.promisify(NodeChildProcess.execFile);
13
14 +const executable = async (file: string, body = "exit 0") => {
15 + await NodeFSP.mkdir(NodePath.dirname(file), { recursive: true });
16 + await NodeFSP.writeFile(file, `#!/bin/sh\n${body}\n`, { mode: 0o755 });
17 +};
18 +
19 +const completeSdk = async (sdk: string, adb = "echo Android Debug Bridge") => {
20 + await executable(NodePath.join(sdk, "platform-tools/adb"), adb);
21 + await executable(NodePath.join(sdk, "emulator/emulator"));
22 + await executable(NodePath.join(sdk, "cmdline-tools/latest/bin/avdmanager"));
23 +};
24 +
25 +/** Runs the probe through the SSH shell setup, then `after` in that same shell. */
26 +const probeAndroid = (setup: (home: string) => Promise<Record<string, string>>, after = "true") =>
27 + Effect.promise(async () => {
28 + const home = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-ssh-sdk-"));
29 + try {
30 + const env = await setup(home);
31 + await executable(NodePath.join(home, "bin/npm"), "echo 10.0.0");
32 + const probe = NodePath.join(home, "probe.cjs");
33 + await NodeFSP.writeFile(probe, remoteDeviceScript("fixture", "probe"));
34 + const result = await exec(
35 + "/bin/sh",
36 + ["-c", `${remoteDeviceEnvironment}\n"$NODE" "$PROBE" && ${after}`],
37 + {
38 + env: {
39 + HOME: home,
40 + PATH: `${NodePath.join(home, "bin")}:/usr/bin:/bin`,
41 + NODE: process.execPath,
42 + PROBE: probe,
43 + ...env,
44 + },
45 + },
46 + );
47 + const [inventory = "", ...rest] = result.stdout.trim().split("\n");
48 + const android = JSON.parse(inventory).platforms.find(
49 + (entry: { platform: string }) => entry.platform === "android",
50 + );
51 + return { android, after: rest.join("\n") };
52 + } finally {
53 + await NodeFSP.rm(home, { recursive: true, force: true });
54 + }
55 + });
56 +
57 +it.effect("does not offer Android when the SDK adb cannot run", () =>
58 + Effect.gen(function* () {
59 + if ((yield* HostProcess.Platform) === "win32") return;
60 + const { android } = yield* probeAndroid(async (home) => {
61 + const sdk = NodePath.join(home, "sdk");
62 + await completeSdk(sdk, "exit 1");
63 + return { ANDROID_HOME: sdk };
64 + });
65 + expect(android).toEqual({ platform: "android", available: false, reason: expect.any(String) });
66 + }),
67 +);
68 +
69 +it.effect("does not offer Android when SDK tools are directories", () =>
70 + Effect.gen(function* () {
71 + if ((yield* HostProcess.Platform) === "win32") return;
72 + const { android } = yield* probeAndroid(async (home) => {
73 + const sdk = NodePath.join(home, "sdk");
74 + await executable(NodePath.join(sdk, "platform-tools/adb"), "echo Android Debug Bridge");
75 + await NodeFSP.mkdir(NodePath.join(sdk, "emulator/emulator"), { recursive: true });
76 + await NodeFSP.mkdir(NodePath.join(sdk, "cmdline-tools/latest/bin/avdmanager"), {
77 + recursive: true,
78 + });
79 + return { ANDROID_HOME: sdk };
80 + });
81 + expect(android).toEqual({
82 + platform: "android",
83 + available: false,
84 + reason: expect.stringContaining("Android Emulator"),
85 + });
86 + }),
87 +);
88 +
89 +it.effect("uses the SDK the probe accepted for later SSH commands", () =>
90 + Effect.gen(function* () {
91 + if ((yield* HostProcess.Platform) === "win32") return;
92 + let sdk = "";
93 + const result = yield* probeAndroid(async (home) => {
94 + // Incomplete default locations must not shadow the configured SDK.
95 + await NodeFSP.mkdir(NodePath.join(home, "Library/Android/sdk"), { recursive: true });
96 + await NodeFSP.mkdir(NodePath.join(home, "Android/Sdk"), { recursive: true });
97 + sdk = NodePath.join(home, "custom-sdk");
98 + await completeSdk(sdk);
99 + return { ANDROID_SDK_ROOT: sdk };
100 + }, "command -v emulator");
101 + expect(result.android).toEqual({ platform: "android", available: true });
102 + expect(result.after).toBe(NodePath.join(sdk, "emulator/emulator"));
103 + }),
104 +);
105 +
106 it.effect("finds Android Studio Java for a non-interactive SSH session", () =>
107 Effect.gen(function* () {
108 if ((yield* HostProcess.Platform) === "win32") return;
@@ -96,7 +188,7 @@ if (fs.existsSync(${JSON.stringify(failMarker)})) process.exitCode = 1;`,
188 expect(start().stderr).toContain("Could not stop the agent-device daemon");
189 expect(await NodeFSP.readFile(daemonFile, "utf8")).toContain("claims");
190 await NodeFSP.rm(failMarker);
99 - expect(start().stderr).toContain("Android SDK missing");
191 + expect(start().stderr).toContain("Android SDK was not found");
192 await expect(NodeFSP.access(daemonFile)).rejects.toThrow();
193 expect(await NodeFSP.readFile(calls, "utf8")).toBe(
194 `daemon stop --state-dir ${state}\ndaemon stop --state-dir ${state}\n`,
@@ -139,7 +231,7 @@ it.effect("keeps a daemon record its missing agent CLI cannot stop", () =>
231 );
232 expect(await NodeFSP.readFile(daemonFile, "utf8")).toContain("claims");
233 const exited = NodeChildProcess.spawnSync(process.execPath, ["-e", ""]).pid;
142 - expect((await start(exited)).stderr).toContain("Android SDK missing");
234 + expect((await start(exited)).stderr).toContain("Android SDK was not found");
235 await expect(NodeFSP.access(daemonFile)).rejects.toThrow();
236 } finally {
237 await NodeFSP.rm(home, { recursive: true, force: true });
apps/server/src/device/sshDeviceScript.ts
+21 -3
@@ -5,7 +5,8 @@ export const quoteRemoteArg = (value: string) => `'${value.replaceAll("'", "'\"'
5
6 export const remoteDeviceEnvironment = `export PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"
7 if [ -z "$ANDROID_HOME" ]; then
8 - if [ -d "$HOME/Library/Android/sdk" ]; then export ANDROID_HOME="$HOME/Library/Android/sdk";
8 + if [ -n "$ANDROID_SDK_ROOT" ]; then export ANDROID_HOME="$ANDROID_SDK_ROOT";
9 + elif [ -d "$HOME/Library/Android/sdk" ]; then export ANDROID_HOME="$HOME/Library/Android/sdk";
10 elif [ -d "$HOME/Android/Sdk" ]; then export ANDROID_HOME="$HOME/Android/Sdk"; fi
11 fi
12 if [ -n "$ANDROID_HOME" ]; then export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"; fi
@@ -133,10 +134,27 @@ async function install(name, version, entry) {
134 }
135 (async () => {
136 const ios = process.platform === 'darwin' && run('xcrun', ['simctl', 'help']).status === 0;
136 - const android = run('adb', ['version']).status === 0;
137 + // The SSH shell setup chose ANDROID_HOME, so later commands use the SDK accepted here.
138 + const sdk = process.env.ANDROID_HOME;
139 + const executable = (relative) => {
140 + try {
141 + const file = path.join(sdk, relative);
142 + fs.accessSync(file, fs.constants.X_OK);
143 + return fs.statSync(file).isFile();
144 + } catch {
145 + return false;
146 + }
147 + };
148 + const androidReason = !sdk ? 'Android SDK was not found. Install it with Android Studio or set ANDROID_HOME on the SSH host.'
149 + : !executable('platform-tools/adb') ? 'Android SDK Platform-Tools are missing from ' + sdk + '. Install them in Android Studio SDK Manager.'
150 + : !executable('emulator/emulator') ? 'Android Emulator is missing from ' + sdk + '. Install it in Android Studio SDK Manager.'
151 + : !executable('cmdline-tools/latest/bin/avdmanager') ? 'Android SDK Command-line Tools (latest) are missing from ' + sdk + '. Install them in Android Studio SDK Manager.'
152 + : run(path.join(sdk, 'platform-tools', 'adb'), ['version']).status !== 0 ? 'adb in ' + sdk + ' failed to run. Reinstall Android SDK Platform-Tools.'
153 + : null;
154 + const android = androidReason === null;
155 const platforms = [
156 { platform: 'ios', available: ios, ...(!ios ? { reason: 'iOS needs macOS with Xcode and working xcrun simctl.' } : {}) },
139 - { platform: 'android', available: android, ...(!android ? { reason: 'Android SDK missing. Set ANDROID_HOME or put adb on the SSH PATH.' } : {}) },
157 + { platform: 'android', available: android, ...(!android ? { reason: androidReason } : {}) },
158 ];
159 if (mode === 'probe') {
160 const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(Number);
docs/user/devices.md
+3 -1
@@ -112,7 +112,9 @@ SSH device hosts currently need macOS or Linux. To use devices on a Windows
112 machine, run T3 Code on that machine and connect to its environment.
113 Node 22.12 or newer and npm must be available to non-interactive SSH commands.
114 T3 checks common Homebrew and Android SDK locations; custom installations need
115 -the appropriate PATH and ANDROID_HOME on the host. Android emulator video needs
115 +the appropriate PATH and `ANDROID_HOME` or `ANDROID_SDK_ROOT` on the host.
116 +Android on an SSH host needs the same SDK tools as a local environment; adb on
117 +the PATH alone does not enable it. Android emulator video needs
118 `ffmpeg` with libx264 on that host; physical Android devices use scrcpy and do
119 not need ffmpeg.
120