scripts: self-contained in-repo build_emu.sh (replaces /tmp recipe)

The Android build recipe lived at /tmp/build_pad.sh and depended on
/tmp/apktool.jar; /tmp gets wiped between sessions (both were lost once
mid-project and had to be rebuilt). Move the recipe into the repo as
scripts/build_emu.sh:

- checks prerequisites (java, gogio, apksigner, adb, debug keystore) with
  actionable error messages
- auto-downloads apktool v3.0.3 to the stable ~/android-sdk/tools/ if
  missing (never /tmp)
- uses a mktemp work dir cleaned via trap; no /tmp clutter
- --no-install flag; verifies an adb device is present before installing
- verifies the permission injection actually took effect

Tested end-to-end (build + install + app relaunch) and idempotent on
re-run. doc/README.md and development_plan.md now point here.
This commit is contained in:
gmp
2026-08-16 21:14:25 -04:00
parent c22c21c872
commit 3a39fb8126
3 changed files with 98 additions and 15 deletions
+14 -12
View File
@@ -38,21 +38,23 @@ line-by-line code — so they stay true as the implementation evolves.
Prereqs on this box (already installed): JDK 17, Go, Android SDK at
`~/android-sdk` (platform-tools, build-tools 35.0.0, emulator, NDK),
`gogio@v0.10.0` in `~/go/bin`, `apktool` at `/tmp/apktool.jar`, debug
keystore at `~/.android/debug.keystore`. Env vars are set in `~/.bashrc`.
`gogio@v0.10.0` in `~/go/bin`, debug keystore at
`~/.android/debug.keystore`. Env vars are set in `~/.bashrc`.
The full recipe is `/tmp/build_pad.sh` (machine-local). Steps:
**Build + install with `./scripts/build_emu.sh`** (add `--no-install` to
build only). It is self-contained: checks the prereqs, auto-downloads
apktool v3.0.3 to `~/android-sdk/tools/apktool.jar` if missing, and uses a
temporary work dir. Output: `cmd/pad/pad-emu.apk`.
1. `gogio -target android -targetsdk 35 -arch amd64 -o /tmp/pad-raw.apk .`
(from `cmd/pad/`)
2. `apktool d /tmp/pad-raw.apk -o /tmp/pad_decoded -f`
What it does, and why (gogio cannot inject manifest permissions):
1. `gogio -target android -targetsdk 35 -arch amd64` → raw APK (from `cmd/pad/`)
2. `apktool d` → decode
3. Inject `<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>`
into the decoded `AndroidManifest.xml` (Android 15 needs it for
`/storage/emulated/0`).
4. `apktool b /tmp/pad_decoded -o /tmp/pad-unsigned.apk`
5. `apksigner sign --ks ~/.android/debug.keystore --ks-pass pass:android
--key-pass pass:android --ks-key-alias androiddebugkey --out cmd/pad/pad-emu.apk /tmp/pad-unsigned.apk`
6. `adb install -r cmd/pad/pad-emu.apk`
(without it, Android 11+ blocks listing `/storage/emulated/0`)
4. `apktool b` → rebuild
5. `apksigner sign` with the debug key → `cmd/pad/pad-emu.apk`
6. `adb install -r` (skipped with `--no-install`)
Run the emulator (headless, AVD `pad_avd`, API 35):
+3 -3
View File
@@ -153,7 +153,7 @@ API 35 `google_apis/x86_64` system image installed to `~/android-sdk`; AVD
`pad_avd` (Pixel 6 profile) boots with KVM (`/dev/kvm` chmod 666). Build recipe:
`gogio -target android -targetsdk 35 -arch amd64` → inject
`MANAGE_EXTERNAL_STORAGE` via apktool → sign with the debug keystore →
`adb install -r` (scripted in `/tmp/build_pad.sh`).
`adb install -r` (scripted in `scripts/build_emu.sh`).
**On-device IME validation — PASSING** (Gboard, API 35; observed via the gated
`imeDebugLog` trace + logcat + autosaved file diff + screenshots):
@@ -248,8 +248,8 @@ but are not needed for a usable v1.
rules; over-detailed companion docs deleted — see `doc/README.md` policy).
- ✓ Amend `spec.md` per §7 (2026-08-16: rewritten; unbuilt features moved to an
explicit “deferred” table; see the corrections noted under §7 below).
- ✓ Build/install recipe (2026-08-16: in `doc/README.md`; machine-local script
`/tmp/build_pad.sh`).
- ✓ Build/install recipe (2026-08-16: in `doc/README.md`; self-contained
in-repo script `scripts/build_emu.sh`).
- ☐ In-repo device test checklist (the adb tap/swipe/IME sequences used in
Phases 2–3 and Phase 6 are in this plan's phase notes but not a standalone
checklist).