Skip to content

Commit 844ea28

Browse files
Move Android WebView app to ci/android
1 parent e5dc516 commit 844ea28

12 files changed

Lines changed: 322 additions & 120 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build Android WebView APK
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- "ci/android/**"
8+
- ".github/workflows/android-webview.yaml"
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build-apk:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: ci/android
19+
steps:
20+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
21+
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6
22+
with:
23+
node-version-file: .node-version
24+
# TODO: pin these two actions to commit SHAs like the rest of this repo.
25+
- uses: actions/setup-java@v4
26+
with:
27+
distribution: temurin
28+
java-version: "17"
29+
30+
# The Android SDK is preinstalled on ubuntu-latest runners.
31+
- name: Set Android SDK env
32+
run: |
33+
echo "ANDROID_SDK_ROOT=$ANDROID_HOME" >> "$GITHUB_ENV"
34+
35+
- name: Install dependencies
36+
run: npm install
37+
38+
- name: Add Android platform
39+
run: npx cap add android
40+
41+
- name: Sync Capacitor
42+
run: npx cap sync android
43+
44+
# Cleartext traffic is needed because code-server is served over plain
45+
# HTTP on localhost. Capacitor may already set this from
46+
# `server.cleartext`; only patch the manifest if it did not.
47+
- name: Ensure cleartext traffic and INTERNET permission
48+
run: |
49+
manifest=android/app/src/main/AndroidManifest.xml
50+
grep -q 'usesCleartextTraffic' "$manifest" || \
51+
sed -i 's/<application/<application android:usesCleartextTraffic="true"/' "$manifest"
52+
grep -q 'android.permission.INTERNET' "$manifest" || \
53+
sed -i 's#</manifest># <uses-permission android:name="android.permission.INTERNET" />\n</manifest>#' "$manifest"
54+
grep -n 'usesCleartextTraffic\|INTERNET' "$manifest"
55+
56+
- name: Build debug APK
57+
run: |
58+
chmod +x android/gradlew
59+
cd android
60+
./gradlew assembleDebug
61+
62+
- uses: actions/upload-artifact@v4 # TODO: pin to a commit SHA
63+
with:
64+
name: code-server-android-webview-debug
65+
path: ci/android/android/app/build/outputs/apk/debug/app-debug.apk

‎.github/workflows/build-apk.yaml‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎android-manifest-ref/AndroidManifest-changes.xml‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎capacitor.config.ts‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎ci/android/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
# Generated by `npx cap add android`.
3+
android

‎ci/android/README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Android WebView wrapper
2+
3+
A minimal [Capacitor](https://capacitorjs.com) app that opens a code-server
4+
instance running on the same device (for example in
5+
[Termux](../../docs/termux.md)) inside a WebView.
6+
7+
It does **not** bundle Node.js or code-server, so none of the Node.js Mobile
8+
API limitations apply. code-server runs as a normal process in Termux and
9+
terminals, language servers, and sockets behave as they do on any Linux system.
10+
11+
See [docs/android-webview.md](../../docs/android-webview.md) for usage.
12+
13+
## Build locally
14+
15+
Requires Node.js, JDK 17, and the Android SDK.
16+
17+
```shell
18+
cd ci/android
19+
npm install
20+
npx cap add android
21+
npx cap sync android
22+
cd android
23+
./gradlew assembleDebug
24+
```
25+
26+
The APK is written to `android/app/build/outputs/apk/debug/app-debug.apk`.
27+
28+
The same steps run in the `Build Android WebView APK` GitHub workflow.

‎ci/android/capacitor.config.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { CapacitorConfig } from "@capacitor/cli"
2+
3+
// This app is a thin WebView wrapper. It does not bundle code-server or Node.
4+
// It loads a code-server instance that is already running on the device
5+
// (for example in Termux) at http://127.0.0.1:8080.
6+
const config: CapacitorConfig = {
7+
appId: "com.coder.codeserver",
8+
appName: "code-server",
9+
webDir: "www",
10+
server: {
11+
url: "http://127.0.0.1:8080",
12+
cleartext: true,
13+
},
14+
android: {
15+
allowMixedContent: true,
16+
},
17+
}
18+
19+
export default config

‎ci/android/package.json‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "code-server-android-webview",
3+
"private": true,
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"description": "Android WebView wrapper that connects to a code-server instance running on the device",
7+
"scripts": {
8+
"sync": "cap sync android",
9+
"open": "cap open android"
10+
},
11+
"dependencies": {
12+
"@capacitor/android": "^6.0.0",
13+
"@capacitor/core": "^6.0.0"
14+
},
15+
"devDependencies": {
16+
"@capacitor/cli": "^6.0.0",
17+
"typescript": "^5.6.2"
18+
}
19+
}

‎ci/android/www/index.html‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6+
<title>code-server</title>
7+
</head>
8+
<body>
9+
<!--
10+
Placeholder only. When the app starts, Capacitor loads server.url from
11+
capacitor.config.ts (http://127.0.0.1:8080), which is the code-server
12+
instance running on the device. This page is never shown.
13+
-->
14+
<p>Loading code-server...</p>
15+
</body>
16+
</html>

‎docs/android-webview.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Android WebView app
2+
3+
A small Android app that opens a locally running code-server in a WebView, so
4+
you get a full-screen app instead of a browser tab.
5+
6+
The app does **not** bundle code-server or Node.js (it does not use Node.js
7+
Mobile). You run code-server on the device yourself, normally in
8+
[Termux](./termux.md), where terminals, language servers, and sockets work as
9+
on any Linux system. The app only displays `http://127.0.0.1:8080`.
10+
11+
## Usage
12+
13+
1. Install code-server in Termux by following the [Termux guide](./termux.md).
14+
code-server requires Node.js 24; check with `node -v`.
15+
2. Set a password in `~/.config/code-server/config.yaml` and keep
16+
`auth: password`. Any app on the device can reach `127.0.0.1:8080`, so do not
17+
disable authentication.
18+
3. Start code-server in Termux: `code-server`.
19+
4. Open the app. It loads `http://127.0.0.1:8080`.
20+
21+
If you change the port in `bind-addr`, rebuild the app with the matching
22+
`server.url` in [`ci/android/capacitor.config.ts`](../ci/android/capacitor.config.ts).
23+
24+
## Building
25+
26+
See [`ci/android/README.md`](../ci/android/README.md). The `Build Android
27+
WebView APK` workflow builds a debug APK and uploads it as an artifact.

0 commit comments

Comments
 (0)