Add Android control app and embedded server

Inspired by HNKServer/honoka-chan-apk-server, but implemented as a JNI-based embedded runtime instead of the original approach.

- Add an Android Compose controller app that starts and stops honoka-chan through JNI, shows runtime and health status, manages data directory mounting, and supports backup import/export for data.db
- Add an embeddable Go server entrypoint plus JNI-exported status, health, and reload hooks so desktop and Android builds share the same startup and shutdown path
- Add Android build scripts, runtime packaging, and project documentation, including generated default config.json content for honoka_runtime.zip
- Add runtime bundle hash tracking so updated honoka_runtime.zip assets are automatically redeployed while preserving config.json and user data files
- Add in-app service settings for unlock_all_special_rotation with immediate config persistence and automatic reload when the service is running
- Split SQLite driver selection by platform, using go-sqlite3 on Android and modernc.org/sqlite elsewhere to avoid Android x86_64 seccomp crashes
- Update startup, database initialization, and system health/reload handlers to support the embedded runtime and Android control flow

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-06-12 19:17:21 +08:00
parent 5c2d68f979
commit 91bbc7f607
64 changed files with 3230 additions and 286 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh"
log "step 1/4: prepare runtime zip"
"$SCRIPT_DIR/prepare_runtime_zip.sh"
log "step 2/4: build Go library arm64-v8a"
"$SCRIPT_DIR/build_go_android.sh" arm64-v8a
log "step 3/4: build Go library armeabi-v7a"
"$SCRIPT_DIR/build_go_android.sh" armeabi-v7a
log "step 4/4: build Go library x86_64"
"$SCRIPT_DIR/build_go_android.sh" x86_64
log "android runtime assets and JNI libraries are ready"
log "open android/ in Android Studio to build the APK"
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh"
require_cmd go
ABI="${1:-arm64-v8a}"
MIN_SDK="${MIN_SDK:-26}"
NDK_ROOT="${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}"
[[ -n "$NDK_ROOT" ]] || die "ANDROID_NDK_HOME is not set"
[[ -d "$NDK_ROOT" ]] || die "ANDROID_NDK_HOME does not exist: $NDK_ROOT"
HOST_TAG="${ANDROID_NDK_HOST_TAG:-linux-x86_64}"
TOOLCHAIN="$NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG/bin"
[[ -d "$TOOLCHAIN" ]] || die "NDK toolchain not found: $TOOLCHAIN"
case "$ABI" in
arm64-v8a)
export GOOS=android
export GOARCH=arm64
export CGO_ENABLED=1
export CC="$TOOLCHAIN/aarch64-linux-android${MIN_SDK}-clang"
OUTPUT_DIR="$ANDROID_DIR/app/src/main/jniLibs/arm64-v8a"
;;
armeabi-v7a)
export GOOS=android
export GOARCH=arm
export GOARM=7
export CGO_ENABLED=1
export CC="$TOOLCHAIN/armv7a-linux-androideabi${MIN_SDK}-clang"
OUTPUT_DIR="$ANDROID_DIR/app/src/main/jniLibs/armeabi-v7a"
;;
x86_64)
export GOOS=android
export GOARCH=amd64
export CGO_ENABLED=1
export CC="$TOOLCHAIN/x86_64-linux-android${MIN_SDK}-clang"
OUTPUT_DIR="$ANDROID_DIR/app/src/main/jniLibs/x86_64"
;;
*)
die "unsupported abi: $ABI"
;;
esac
[[ -x "$CC" ]] || die "clang not found: $CC"
mkdir -p "$OUTPUT_DIR"
cd "$PROJECT_ROOT"
log "building Go shared library for $ABI"
go build -trimpath -buildmode=c-shared \
-ldflags="-s -w" \
-o "$OUTPUT_DIR/libhonokachan.so" \
./cmd/honoka-android
rm -f "$OUTPUT_DIR/libhonokachan.h"
log "built $OUTPUT_DIR/libhonokachan.so"
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh"
ok() {
printf '[android] ok: %s\n' "$*"
}
warn() {
printf '[android] warn: %s\n' "$*" >&2
}
status=0
check_cmd() {
local cmd="$1"
if command -v "$cmd" >/dev/null 2>&1; then
ok "command found: $cmd -> $(command -v "$cmd")"
else
warn "command missing: $cmd"
status=1
fi
}
check_file() {
local file="$1"
if [[ -f "$file" ]]; then
ok "file found: $file"
else
warn "file missing: $file"
status=1
fi
}
check_dir() {
local dir="$1"
if [[ -d "$dir" ]]; then
ok "directory found: $dir"
else
warn "directory missing: $dir"
status=1
fi
}
log "checking common commands"
check_cmd go
check_cmd zip
SDK_ROOT="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"
NDK_ROOT="${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}"
HOST_TAG="${ANDROID_NDK_HOST_TAG:-linux-x86_64}"
MIN_SDK="${MIN_SDK:-26}"
if [[ -n "$SDK_ROOT" ]]; then
check_dir "$SDK_ROOT"
else
warn "ANDROID_SDK_ROOT is not set"
status=1
fi
if [[ -n "$NDK_ROOT" ]]; then
check_dir "$NDK_ROOT"
TOOLCHAIN="$NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG/bin"
check_dir "$TOOLCHAIN"
check_file "$TOOLCHAIN/aarch64-linux-android${MIN_SDK}-clang"
check_file "$TOOLCHAIN/armv7a-linux-androideabi${MIN_SDK}-clang"
check_file "$TOOLCHAIN/x86_64-linux-android${MIN_SDK}-clang"
else
warn "ANDROID_NDK_HOME is not set"
status=1
fi
log "checking project files"
check_file "$PROJECT_ROOT/assets/main.db"
check_dir "$PROJECT_ROOT/assets/serverdata"
check_dir "$PROJECT_ROOT/assets/certs"
check_dir "$PROJECT_ROOT/static/templates"
if [[ $status -ne 0 ]]; then
warn "environment check failed"
exit $status
fi
ok "environment check passed"
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
ANDROID_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
PROJECT_ROOT="$(cd -- "$ANDROID_DIR/.." && pwd)"
readonly SCRIPT_DIR
readonly ANDROID_DIR
readonly PROJECT_ROOT
log() {
printf '[android] %s\n' "$*"
}
die() {
printf '[android] error: %s\n' "$*" >&2
exit 1
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || die "missing command: $1"
}
ensure_file() {
[[ -f "$1" ]] || die "missing file: $1"
}
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh"
require_cmd zip
ZIP_PATH="$ANDROID_DIR/app/src/main/assets/honoka_runtime.zip"
cd "$PROJECT_ROOT"
ensure_file "$PROJECT_ROOT/assets/main.db"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
mkdir -p "$TMP_DIR/assets" "$TMP_DIR/static"
log "collecting runtime files"
cat > "$TMP_DIR/config.json" <<'EOF'
{
"app_name": "honoka-chan",
"settings": {
"listen_port": "8080",
"cdn_server": "http://127.0.0.1:8080/static",
"reload_token": "",
"unlock_all_special_rotation": false
}
}
EOF
cp -r "$PROJECT_ROOT/assets/main.db" "$TMP_DIR/assets/main.db"
for path in \
"assets/serverdata" \
"assets/certs" \
"static/templates" \
"static/css" \
"static/js" \
"static/images" \
"static/font"
do
if [[ -e "$PROJECT_ROOT/$path" ]]; then
mkdir -p "$TMP_DIR/$(dirname "$path")"
cp -r "$PROJECT_ROOT/$path" "$TMP_DIR/$path"
fi
done
rm -f "$ZIP_PATH"
log "packing $ZIP_PATH"
(
cd "$TMP_DIR"
zip -qr "$ZIP_PATH" assets static config.json
)
log "runtime zip ready: $ZIP_PATH"