Files
oott/frontend/run_android_emulator.sh
T
rzuastiandClaude Opus 4.8 2817fc7cab Fix Android emulator app launch
Three issues prevented `run_android_emulator.sh` from launching the app:

- gradlew's shebang was a hardcoded Nix-store bash path (copied verbatim
  from the nixpkgs Flutter SDK template) that breaks once that store path
  is garbage-collected, surfacing as a misleading "ProcessException: No
  such file or directory". The dev-shell now normalizes the gitignored
  android/gradlew shebang to the portable "#!/usr/bin/env sh" on entry.
- `flutter run -d android` never matched: -d resolves a device by id/name,
  not platform. Resolve the concrete id (e.g. emulator-5554) from
  `flutter devices --machine` instead.
- Install raced the boot ("device is still booting"); wait for
  sys.boot_completed=1 before launching.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 09:35:46 -04:00

65 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Run the OOTT front-end on the Android emulator.
#
# Boots the emulator first (via run_android.sh) if it isn't already running,
# then launches the Flutter app on it. Any extra arguments are forwarded to
# `flutter run`.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if ! command -v flutter >/dev/null 2>&1; then
echo "error: 'flutter' not found on PATH." >&2
echo " Enter the dev shell first (e.g. 'nix develop')." >&2
exit 1
fi
# Print the id of the first connected Android device, or nothing if none is up.
# `flutter run -d <x>` matches a device by id/name, never by platform, so the
# literal "android" is not a usable target; we must resolve the concrete id
# (e.g. "emulator-5554") from flutter's own machine-readable device list.
android_device_id() {
flutter devices --machine 2>/dev/null | python3 -c '
import json, sys
try:
devices = json.load(sys.stdin)
except ValueError:
devices = []
for d in devices:
if str(d.get("targetPlatform", "")).startswith("android"):
print(d["id"])
break
'
}
# Block until the Android OS on the given device has finished booting. The
# device shows up in `flutter devices` as soon as adb connects, but installing
# before boot completes fails with "device is still booting", so we poll the
# sys.boot_completed property (adb shell emits CRLF, hence the trailing-\r trim).
wait_for_boot() {
local serial="$1"
adb -s "$serial" wait-for-device
until [ "$(adb -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = "1" ]; do
sleep 2
done
}
# Boot the emulator in the background if no Android device is connected yet.
if [ -z "$(android_device_id)" ]; then
echo "No Android device detected, booting the emulator..."
"$SCRIPT_DIR/run_android.sh" -no-snapshot-save &
echo "Waiting for the emulator to come online..."
until [ -n "$(android_device_id)" ]; do
sleep 2
done
fi
device_id="$(android_device_id)"
echo "Waiting for '$device_id' to finish booting..."
wait_for_boot "$device_id"
echo "Launching OOTT on '$device_id'..."
exec flutter run -d "$device_id" "$@"