49 lines
1.8 KiB
Bash
Executable File
49 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# Builds this app and runs it on this checkout's emulator.
|
|
#
|
|
# The emulator half of this -- which AVD this checkout means, creating it,
|
|
# booting it headless, and refusing to start one the machine has no room for
|
|
# -- lives in ~/repos/emulator-tools and is shared with every other Android
|
|
# checkout here. This script kept its own copy of that sequence until
|
|
# 2026-08-30, as did dev-updater's and ai-app's, and three copies of "boot an
|
|
# emulator" is three places for the memory check that was missing from all of
|
|
# them.
|
|
#
|
|
# Environment machine (SDK location, PATH, ...) lives in ./android-env.sh,
|
|
# which can also be sourced directly for one-off commands.
|
|
set -eu
|
|
|
|
APP_ID="com.example.aiapp"
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
|
cd "$SCRIPT_DIR"
|
|
|
|
# shellcheck source=./android-env.sh
|
|
. ./android-env.sh
|
|
|
|
if ! command -v emu >/dev/null 2>&1; then
|
|
echo "run-android.sh: no 'emu' command." >&2
|
|
echo " It comes from ~/repos/emulator-tools; run that repo's ./install.sh." >&2
|
|
exit 127
|
|
fi
|
|
|
|
# Prints the serial, having created and booted the AVD if it had to. Named
|
|
# after the checkout, so this cannot land on another session's emulator --
|
|
# and refuses rather than starting one when the machine is short of memory,
|
|
# because what an OOM kills is somebody else's work rather than the emulator
|
|
# that asked for the memory.
|
|
echo "==> Emulator"
|
|
SERIAL=$(emu up)
|
|
export ANDROID_SERIAL="$SERIAL"
|
|
|
|
echo "==> Building debug APK"
|
|
./gradlew :androidApp:assembleDebug
|
|
|
|
APK="androidApp/build/outputs/apk/debug/androidApp-debug.apk"
|
|
echo "==> Installing and launching $APK"
|
|
# ANDROID_SERIAL above is what aims these; the adb wrapper would work it out
|
|
# from the checkout anyway, but a script that says which device it means does
|
|
# not depend on being run from the right directory.
|
|
adb install -r "$APK"
|
|
adb shell am start -n "$APP_ID/.MainActivity"
|