Skip to content

Commit b7c6eb8

Browse files
authored
Merge pull request #2 from grand151/copilot/develop-opencode-android-arm64
Add Android ARM64 platform support
2 parents d366a14 + 52cfe26 commit b7c6eb8

4 files changed

Lines changed: 53 additions & 13 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Then run it with:
6767
./packages/opencode/dist/opencode-<platform>/bin/opencode
6868
```
6969

70-
Replace `<platform>` with your platform (e.g., `darwin-arm64`, `linux-x64`).
70+
Replace `<platform>` with your platform (e.g., `darwin-arm64`, `linux-x64`, `android-arm64`).
7171

7272
- Core pieces:
7373
- `packages/opencode`: OpenCode core business logic & server.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ nix run nixpkgs#opencode # or github:anomalyco/opencode for latest dev
6161
> [!TIP]
6262
> Remove versions older than 0.1.x before installing.
6363
64+
#### Android/Termux
65+
66+
OpenCode can be installed on Android ARM64 devices using Termux:
67+
68+
```bash
69+
# In Termux
70+
curl -fsSL https://opencode.ai/install | bash
71+
```
72+
73+
> [!NOTE]
74+
> The Android build is based on the Linux ARM64 binary and may require proot-distro for full compatibility. Direct execution in Termux may have limitations due to Android's security model. For best results, consider using proot-distro with Alpine Linux.
75+
6476
### Desktop App (BETA)
6577

6678
OpenCode is also available as a desktop application. Download directly from the [releases page](https://github.com/anomalyco/opencode/releases) or [opencode.ai/download](https://opencode.ai/download).

install

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,22 @@ if [ -n "$binary_path" ]; then
7878
else
7979
raw_os=$(uname -s)
8080
os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]')
81+
82+
# Check if running on Android (e.g., Termux)
83+
is_android=false
84+
if [ -d /system/app ] && [ -d /system/priv-app ]; then
85+
is_android=true
86+
fi
87+
8188
case "$raw_os" in
8289
Darwin*) os="darwin" ;;
83-
Linux*) os="linux" ;;
90+
Linux*)
91+
if [ "$is_android" = "true" ]; then
92+
os="android"
93+
else
94+
os="linux"
95+
fi
96+
;;
8497
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
8598
esac
8699

@@ -101,16 +114,19 @@ else
101114

102115
combo="$os-$arch"
103116
case "$combo" in
104-
linux-x64|linux-arm64|darwin-x64|darwin-arm64|windows-x64)
117+
linux-x64|linux-arm64|darwin-x64|darwin-arm64|windows-x64|android-arm64)
105118
;;
106119
*)
107120
echo -e "${RED}Unsupported OS/Arch: $os/$arch${NC}"
121+
if [ "$is_android" = "true" ] && [ "$arch" != "arm64" ]; then
122+
echo -e "${MUTED}Note: OpenCode on Android/Termux currently only supports ARM64 architecture.${NC}"
123+
fi
108124
exit 1
109125
;;
110126
esac
111127

112128
archive_ext=".zip"
113-
if [ "$os" = "linux" ]; then
129+
if [ "$os" = "linux" ] || [ "$os" = "android" ]; then
114130
archive_ext=".tar.gz"
115131
fi
116132

@@ -158,17 +174,20 @@ else
158174
fi
159175

160176
target="$os-$arch"
161-
if [ "$needs_baseline" = "true" ]; then
162-
target="$target-baseline"
163-
fi
164-
if [ "$is_musl" = "true" ]; then
165-
target="$target-musl"
177+
# Android doesn't need baseline or musl variants
178+
if [ "$os" != "android" ]; then
179+
if [ "$needs_baseline" = "true" ]; then
180+
target="$target-baseline"
181+
fi
182+
if [ "$is_musl" = "true" ]; then
183+
target="$target-musl"
184+
fi
166185
fi
167186

168187
filename="$APP-$target$archive_ext"
169188

170189

171-
if [ "$os" = "linux" ]; then
190+
if [ "$os" = "linux" ] || [ "$os" = "android" ]; then
172191
if ! command -v tar >/dev/null 2>&1; then
173192
echo -e "${RED}Error: 'tar' is required but not installed.${NC}"
174193
exit 1
@@ -334,7 +353,7 @@ download_and_install() {
334353
curl -# -L -o "$tmp_dir/$filename" "$url"
335354
fi
336355

337-
if [ "$os" = "linux" ]; then
356+
if [ "$os" = "linux" ] || [ "$os" = "android" ]; then
338357
tar -xzf "$tmp_dir/$filename" -C "$tmp_dir"
339358
else
340359
unzip -q "$tmp_dir/$filename" -d "$tmp_dir"

packages/opencode/script/build.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ const allTargets: {
6060
arch: "arm64" | "x64"
6161
abi?: "musl"
6262
avx2?: false
63+
android?: boolean
6364
}[] = [
6465
{
6566
os: "linux",
6667
arch: "arm64",
6768
},
69+
{
70+
os: "linux",
71+
arch: "arm64",
72+
android: true,
73+
},
6874
{
6975
os: "linux",
7076
arch: "x64",
@@ -146,7 +152,7 @@ for (const item of targets) {
146152
const name = [
147153
pkg.name,
148154
// changing to win32 flags npm for some reason
149-
item.os === "win32" ? "windows" : item.os,
155+
item.os === "win32" ? "windows" : item.android ? "android" : item.os,
150156
item.arch,
151157
item.avx2 === false ? "baseline" : undefined,
152158
item.abi === undefined ? undefined : item.abi,
@@ -163,6 +169,9 @@ for (const item of targets) {
163169
const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/"
164170
const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/")
165171

172+
// For Android, use the linux-arm64 target as Bun doesn't have native Android support
173+
const buildTarget = item.android ? "bun-linux-arm64" : name.replace(pkg.name, "bun")
174+
166175
await Bun.build({
167176
conditions: ["browser"],
168177
tsconfig: "./tsconfig.json",
@@ -174,7 +183,7 @@ for (const item of targets) {
174183
//@ts-ignore (bun types aren't up to date)
175184
autoloadTsconfig: true,
176185
autoloadPackageJson: true,
177-
target: name.replace(pkg.name, "bun") as any,
186+
target: buildTarget as any,
178187
outfile: `dist/${name}/bin/opencode`,
179188
execArgv: [`--user-agent=opencode/${Script.version}`, "--use-system-ca", "--"],
180189
windows: {},

0 commit comments

Comments
 (0)