Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,34 @@ jobs:
- run: npm install --ignore-scripts --no-audit --no-fund
- run: npm --prefix apps/android/ui ci --legacy-peer-deps --no-audit --no-fund
- run: npm run build
- run: apps/android/gradlew -p apps/android --no-daemon assembleDebug assembleRelease lintDebug testDebugUnitTest
- name: Verify signed Release APK size
- name: Build and lint aBridge Android
run: apps/android/gradlew -p apps/android --no-daemon assembleDebug assembleRelease lintDebug testDebugUnitTest
- name: Build and lint AI Home Android
run: apps/controller/gradlew -p apps/controller --no-daemon assembleDebug assembleRelease lintDebug testDebugUnitTest
- name: "Verify signed APK sizes (aBridge: 300,000 B; AI Home: 2,000,000 B)"
run: |
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
python3 -m venv "$work/python"
"$work/python/bin/python" -m pip install -r tools/android-apk-requirements.txt
keytool -genkeypair -keystore "$work/check.keystore" -alias android -storepass sizecheck -keypass sizecheck \
-keyalg RSA -keysize 2048 -validity 1 -dname "CN=Android size check"
ANDROID_KEYSTORE_BASE64="$(openssl base64 -A -in "$work/check.keystore")" \
ANDROID_KEYSTORE_PASSWORD=sizecheck ANDROID_KEY_ALIAS=android ANDROID_KEY_PASSWORD=sizecheck \
ANDROID_APK_PYTHON="$work/python/bin/python" bash tools/sign-android-release.sh
export ANDROID_KEYSTORE_BASE64="$(openssl base64 -A -in "$work/check.keystore")"
export ANDROID_KEYSTORE_PASSWORD=sizecheck ANDROID_KEY_ALIAS=android ANDROID_KEY_PASSWORD=sizecheck
export ANDROID_APK_PYTHON="$work/python/bin/python"
bash tools/sign-android-release.sh abridge
bash tools/sign-android-release.sh aihome
- name: Upload installable Debug APK
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: abridge-android-debug
path: apps/android/build/outputs/apk/debug/*.apk
if-no-files-found: error
retention-days: 14
- name: Upload installable AI Home Debug APK
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: aihome-android-debug
path: apps/controller/build/outputs/apk/debug/*.apk
if-no-files-found: error
retention-days: 14
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ jobs:
run: |
npm --prefix apps/android/ui ci --legacy-peer-deps --no-audit --no-fund
apps/android/gradlew -p apps/android --no-daemon assembleRelease
apps/controller/gradlew -p apps/controller --no-daemon assembleRelease
python3 -m venv "$RUNNER_TEMP/android-apk-build"
"$RUNNER_TEMP/android-apk-build/bin/python" -m pip install -r tools/android-apk-requirements.txt
ANDROID_APK_PYTHON="$RUNNER_TEMP/android-apk-build/bin/python" bash tools/sign-android-release.sh
export ANDROID_APK_PYTHON="$RUNNER_TEMP/android-apk-build/bin/python"
bash tools/sign-android-release.sh abridge
bash tools/sign-android-release.sh aihome
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
if: runner.os == 'Linux'
with:
Expand All @@ -99,6 +102,7 @@ jobs:
dist/releases/abridge-client-browser-*.tar.gz*
dist/releases/install-browser-client.sh*
dist/releases/aBridge-*-android.apk
dist/releases/AIHome-*-android.apk
if-no-files-found: error
retention-days: 14
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
Expand Down
2 changes: 1 addition & 1 deletion apps/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The Android build requires JDK 17 and Android SDK Platform 36. Gradle consumes t

The [Android App workflow](../../.github/workflows/android.yml) builds Debug and Release APKs and runs Android Lint on pull requests and pushes to `main`. Download the installable Debug APK from the run's **abridge-android-debug** artifact.

Debug and Release APKs use R8 to remove unused code and compress the remaining DEX bytecode. Release packaging recompresses the APK before signing and checks the complete signed file against a 200,000-byte budget. Android extracts the bytecode during installation, so the APK size and installed storage usage differ.
Debug and Release APKs use R8 to remove unused code and compress the remaining DEX bytecode. Release packaging recompresses the APK before signing and checks the complete signed file against a 300,000-byte budget. Android extracts the bytecode during installation, so the APK size and installed storage usage differ.

## Tools

Expand Down
2 changes: 2 additions & 0 deletions apps/controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ cd apps/controller
adb install -r build/outputs/apk/debug/AIHome-debug.apk
```

APK 压缩 DEX 字节码,由 Android 在安装时解压。正式 APK 重新压缩、对齐并签名后,上限为 2,000,000 字节(2 MB,十进制);CI 和发布流程通过 `bash tools/sign-android-release.sh aihome` 检查。aBridge 接收端仍使用独立的 300,000 字节上限。

APK 不包含前端资源。前端由 Server 同源托管,更新后需重新构建并部署 `ui/dist`。安装控制端不会安装或替换接收任务的 aBridge 客户端。

## Server 与工作进程
Expand Down
4 changes: 4 additions & 0 deletions apps/controller/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ android {
versionName upstream
versionCode parts[0] * 1000000 + parts[1] * 1000 + parts[2]
}
packaging {
// Compress DEX in the download; Android extracts it during installation.
dex.useLegacyPackaging = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
Expand Down
41 changes: 18 additions & 23 deletions apps/web/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LayoutDashboard, Monitor, Link2, ListFilter, ShieldCheck } from "lucide
import { VERSION } from "@abridge/protocol";
import { useCallback, useEffect, useState } from "preact/hooks";
import { api, objectResultSchema } from "../lib/api.js";
import { Authentication, ExternalLogin } from "../features/auth/page.js";
import { Authentication, ExternalLogin, SessionLoading } from "../features/auth/page.js";
import { ActionMenu } from "../components/actions.js";
import { Brand } from "../components/brand.js";
import { Field, Form, Modal } from "../components/forms.js";
Expand Down Expand Up @@ -330,7 +330,8 @@ function AdministratorApp() {
return () => window.removeEventListener("hashchange", navigate);
}, []);
const section = parseRoute(hash).id;
if (admin.phase !== "ready")
if (admin.phase === "loading") return <SessionLoading administrator />;
if (admin.phase === "none")
return (
<main class="admin-login" id="main" tabIndex={-1}>
<div class="admin-login-shell">
Expand All @@ -344,27 +345,21 @@ function AdministratorApp() {
<h1 id="admin-login-title">欢迎回来</h1>
<p>使用管理员令牌登录管理后台</p>
</div>
{admin.phase === "loading" ? (
<p role="status">正在验证管理员身份…</p>
) : (
<>
<Form
label="登录"
onSubmit={async (data) => {
setNotice("");
location.hash = new URLSearchParams({
admin_token: String(data.get("token")).trim(),
}).toString();
}}
>
<Field name="token" label="管理员令牌" type="password" passwordPurpose="current" />
</Form>
{notice && (
<p class="error" role="alert">
{notice}
</p>
)}
</>
<Form
label="登录"
onSubmit={async (data) => {
setNotice("");
location.hash = new URLSearchParams({
admin_token: String(data.get("token")).trim(),
}).toString();
}}
>
<Field name="token" label="管理员令牌" type="password" passwordPurpose="current" />
</Form>
{notice && (
<p class="error" role="alert">
{notice}
</p>
)}
</div>
</section>
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/features/admin/console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ export function InstanceAdminPage({
{!rows.length && <p class="admin-empty">没有符合条件的任务</p>}
</div>
);
if (section === "users" || section === "groups")
return (
<>
{!sidebar && <AdminNavigation section={section} />}
{section === "users" ? <UserAdminPage requireLogin={requireLogin} notify={notify} /> : groups}
</>
);
return (
<>
<div class="page-title">
Expand Down Expand Up @@ -395,8 +402,6 @@ export function InstanceAdminPage({
)}
</Modal>
)}
{section === "users" && <UserAdminPage requireLogin={requireLogin} notify={notify} />}
{section === "groups" && groups}
{section === "audit" && (
<section class="surface">
<div class="instance-list-heading">
Expand Down
43 changes: 19 additions & 24 deletions apps/web/src/features/admin/groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,36 @@ import {
} from "@abridge/protocol";
import { api, objectResultSchema } from "../../lib/api.js";
import { Field, Form, Modal } from "../../components/forms.js";
import { RefreshButton } from "./refresh-button.js";

export function GroupsPage({ notify }: { notify: (message: string) => void }) {
const base = "/api/admin/groups";
const [groups, setGroups] = useState<GroupView[]>([]);
const [error, setError] = useState("");
const [loading, setLoading] = useState(true);
const [creating, setCreating] = useState(false);
const [selected, setSelected] = useState<GroupView | null>(null);
const refresh = useCallback(async () => {
const result = await api(base, groupsListSchema);
setGroups(result.groups);
setLoading(true);
try {
const result = await api(base, groupsListSchema);
setGroups(result.groups);
setError("");
} catch (caught) {
setError(caught instanceof Error ? caught.message : "读取小组失败");
} finally {
setLoading(false);
}
}, [base]);
useEffect(() => {
let alive = true;
void api(base, groupsListSchema)
.then((r) => {
if (alive) setGroups(r.groups);
})
.catch((e) => {
if (alive) setError(e instanceof Error ? e.message : "读取小组失败");
});
return () => {
alive = false;
};
}, [base]);
void refresh();
}, [refresh]);
return (
<>
<div class="section-heading">
<h2>全部小组</h2>
<div class="page-title">
<h1>小组</h1>
<div class="actions">
<RefreshButton loading={loading} refresh={refresh} />
<button class="primary" onClick={() => setCreating(true)}>
创建小组
</button>
Expand All @@ -49,13 +50,7 @@ export function GroupsPage({ notify }: { notify: (message: string) => void }) {
{error && (
<p class="error" role="alert">
{error}
<button
onClick={() =>
void refresh()
.then(() => setError(""))
.catch((e) => setError(String(e)))
}
>
<button disabled={loading} onClick={() => void refresh()}>
重试
</button>
</p>
Expand All @@ -72,7 +67,7 @@ export function GroupsPage({ notify }: { notify: (message: string) => void }) {
</div>
</section>
))}
{!groups.length && !error && <p class="admin-empty">暂无小组</p>}
{!groups.length && !error && !loading && <p class="admin-empty">暂无小组</p>}
</div>
{creating && (
<Modal title="创建小组" close={() => setCreating(false)}>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/features/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function UserAdminPage({
return (
<>
<div class="page-title">
<h1>实例管理</h1>
<h1>用户</h1>
<div class="actions">
<RefreshButton loading={loading} refresh={refresh} />
<button class="primary" onClick={() => setCreating(true)}>
Expand Down
20 changes: 11 additions & 9 deletions apps/web/src/features/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export function ExternalLogin() {
</a>
) : null;
}
export function SessionLoading({ administrator = false }: { administrator?: boolean }) {
return (
<main class="login-wrap" id="main" tabIndex={-1} aria-busy="true">
<div class="login-loading" role="status">
<Brand administrator={administrator} />
<p class="muted">{administrator ? "正在加载管理后台…" : "正在加载管理台…"}</p>
</div>
</main>
);
}
export function Authentication({
phase,
notice,
Expand All @@ -37,15 +47,7 @@ export function Authentication({
notice: string;
authenticate: (data: FormData) => Promise<void>;
}) {
if (phase === "loading")
return (
<main class="login-wrap" id="main" tabIndex={-1}>
<div class="login-loading" role="status">
<Brand />
<p class="muted">正在加载管理台…</p>
</div>
</main>
);
if (phase === "loading") return <SessionLoading />;
return (
<main class="login-wrap" id="main" tabIndex={-1}>
<div class="login-panel">
Expand Down
2 changes: 1 addition & 1 deletion docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CI 上传 **windows-client-unsigned**,保留 30 天。tag 发布另将 `aBridg

## Android

发布正式 APK 时,设置 `ANDROID_SIGNING_ENABLED=true`,并配置 `ANDROID_KEYSTORE_BASE64`(密钥库的单行 Base64)、`ANDROID_KEYSTORE_PASSWORD`、`ANDROID_KEY_ALIAS` 和 `ANDROID_KEY_PASSWORD`。工作流重新压缩并对齐 APK,然后签名。在加入 GitHub Release 前,检查 `aBridge-<version>-android.apk` 签名和 200,000 字节的体积上限。
发布正式 APK 时,设置 `ANDROID_SIGNING_ENABLED=true`,并配置 `ANDROID_KEYSTORE_BASE64`(密钥库的单行 Base64)、`ANDROID_KEYSTORE_PASSWORD`、`ANDROID_KEY_ALIAS` 和 `ANDROID_KEY_PASSWORD`。工作流重新压缩并对齐 APK,然后签名。在加入 GitHub Release 前,分别检查 `aBridge-<version>-android.apk` 的 300,000 字节上限和 `AIHome-<version>-android.apk` 的 2,000,000 字节(2 MB,十进制)上限,两者均按完整签名文件计量。签名脚本的 `abridge`(默认)和 `aihome` 参数分别选择对应产物和固定预算。

后续版本继续使用同一签名密钥,已安装用户即可原地升级。Android 安装器会检查包标识、签名和版本。调试 APK 使用开发签名,供本地和 CI 测试。

Expand Down
25 changes: 19 additions & 6 deletions tools/sign-android-release.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

# Keep each product's signed-download budget explicit; no argument retains aBridge.
case "${1:-abridge}" in
abridge)
product=aBridge
limit=300000
unsigned='apps/android/build/outputs/apk/release/aBridge Android-release-unsigned.apk'
;;
aihome)
product=AIHome
limit=2000000
unsigned='apps/controller/build/outputs/apk/release/AIHome-release-unsigned.apk'
;;
*) echo "Usage: $0 [abridge|aihome]" >&2; exit 2 ;;
esac

: "${ANDROID_KEYSTORE_BASE64:?Missing Android release keystore}"
: "${ANDROID_KEYSTORE_PASSWORD:?Missing Android keystore password}"
: "${ANDROID_KEY_ALIAS:?Missing Android signing alias}"
Expand All @@ -9,13 +24,11 @@ set -euo pipefail

version=$(node -p "require('./package.json').version")
build_tools="$ANDROID_HOME/build-tools/36.0.0"
output="dist/releases/aBridge-$version-android.apk"
output="dist/releases/$product-$version-android.apk"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
umask 077
python="${ANDROID_APK_PYTHON:-python3}"
unsigned='apps/android/build/outputs/apk/release/aBridge Android-release-unsigned.apk'

printf '%s' "$ANDROID_KEYSTORE_BASE64" | openssl base64 -d -A > "$work/release.keystore"
"$python" tools/recompress-android-apk.py "$unsigned" "$work/repacked.apk"
"$build_tools/zipalign" -f -P 16 4 "$work/repacked.apk" "$work/aligned.apk"
Expand All @@ -27,10 +40,10 @@ printf '%s' "$ANDROID_KEYSTORE_BASE64" | openssl base64 -d -A > "$work/release.k
--v1-signing-enabled false --v4-signing-enabled false --out "$work/release.apk" "$work/aligned.apk"
"$build_tools/apksigner" verify "$work/release.apk"
size=$(wc -c < "$work/release.apk")
if (( size > 200000 )); then
echo "Signed Android APK is $size bytes and exceeds the 200,000-byte limit." >&2
if (( size > limit )); then
echo "Signed $product Android APK is $size bytes and exceeds the $limit-byte limit ($unsigned)." >&2
exit 1
fi
mkdir -p "$(dirname "$output")"
cp "$work/release.apk" "$output"
echo "Signed Android APK: $size bytes"
echo "Signed $product Android APK: $size bytes (limit: $limit bytes; $output)"
Loading