jtube-tv/scripts/start-emulator.sh
Jeena b84be3e65e scripts: Host-side GPU emulator launcher for scrcpy testing
scrcpy cannot talk to headless emulators inside the container: the
AOSP ATD image lacks framework pieces (KeyCharacterMap NPE) and there
is no GPU/KVM in the container at all. The script boots the android-tv
image image on the host with -gpu host and a window (so the RSA dialog
is clickable), installs the current debug APK and leaves the app
running; the container's socat bridge then exposes it as
rutherford:5556 for adb/scrcpy from anywhere.
2026-10-10 23:26:57 +00:00

70 lines
No EOL
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# start-emulator.sh — boot the JTube TV test emulator on the HOST (not inside the
# agent container), with GPU acceleration and a window. Use this when the app should
# be tested over scrcpy (ATD/system quirks make scrcpy fail against headless
# in-container emulators) or when you simply want to watch it.
#
# The agent container bridges rutherford:5556 -> 127.0.0.1:5601 with socat, so after
# this script the emulator is reachable as:
#
# adb connect rutherford:5556 && scrcpy -s rutherford:5556
#
# An RSA authorization popup appears on the emulator window on first connect —
# click "Always allow"/OK.
set -euo pipefail
SDK="${ANDROID_SDK_ROOT:-$HOME/Android/Sdk}"
EMU="$SDK/emulator/emulator"
ADB="$SDK/platform-tools/adb"
AVD="${1:-jtubesc}"
PORT=5600 # console port; adbd listens on 5601 (the container bridges 5556 -> 5601)
[ -x "$EMU" ] || { echo "emulator not found at $EMU"; exit 1; }
[ -f "$HOME/.android/avd/$AVD.ini" ] || {
echo "AVD $AVD not found; list: (ls ~/.android/avd)"; exit 1; }
# Free stale emulator instances holding our ports (only qemu from OUR SDK path).
for pid in $(ps aux | awk '/[q]emu-system-x86_64/ {print $2}' 2>/dev/null); do
if tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null | grep -q "\-port $PORT"; then
echo "Killing stale emulator pid $pid"
kill -9 "$pid" 2>/dev/null || true
fi
done
sleep 1
ACCEL=()
if [ -e /dev/kvm ]; then
ACCEL+=(-accel kvm); echo "/dev/kvm found — hardware acceleration on"
else
echo "no /dev/kvm — falling back to software rendering (slow)"
fi
echo "Booting AVD '$AVD' on console :$PORT (adbd :$((PORT+1))) …"
setsid nohup "$EMU" -avd "$AVD" -port "$PORT" -gpu host "${ACCEL[@]:-}" \
-no-snapshot > /tmp/jtube-emu.log 2>&1 < /dev/null &
echo "emulator PID $! — log: /tmp/jtube-emu.log"
for i in $(seq 1 90); do
ok=$("$ADB" -s "emulator-$PORT" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')
[ "$ok" = "1" ] && { echo "BOOTED"; break; }
sleep 5
done
# Keep the JTube TV app current + running so scrcpy lands on it.
APK="$HOME/Projects/jtube-tv/app/build/outputs/apk/debug/app-debug.apk"
if [ -f "$APK" ]; then
echo "Installing JTube TV…"
"$ADB" -s "emulator-$PORT" install -r "$APK" >/dev/null && echo "installed"
"$ADB" -s "emulator-$PORT" shell am start -n net.jeena.jtubetv/.MainActivity && echo "app started"
fi
cat <<EOF
Ready. From any machine that can reach rutherford:
adb connect rutherford:5556
scrcpy -s rutherford:5556
If scrcpy says "unauthorized", click the RSA dialog on the emulator window.
EOF