whiskers.git / tools / install-android.sh
1#!/usr/bin/env bash

Install the debug APK on a connected device and start it.

tools/install-android.sh [apk]

Environment (all optional): ADB the adb to use (default: adb on PATH). On WSL this may be the Windows adb.exe. ANDROID_SERIAL which device, when several are connected. WHISKERS_ANDROID_USER the Android user to install for (adb --user N), for a tablet with several profiles. WHISKERS_APP_ID the application id (default app.whiskers; match -Pwhiskers.applicationId if you set it). WHISKERS_STAGE_UNIX / WHISKERS_STAGE_WIN a path for the same file as seen from here and as the Windows adb sees it; set both when ADB is a Windows adb.exe that cannot read WSL paths. The APK is copied there first.

The app needs no address at build time. A build made with -Pwhiskers.host=<host[:port]> only has it as the DEFAULT; an address a grown-up saved in the app wins, and an app with neither asks for one (parents' side, behind the grown-up lock).

-r keeps the app's data across updates. The APK is always signed with the committed debug key, so an update installs over an earlier one; if Android says the signatures differ, uninstall first.

20set -euo pipefail
21cd "$(dirname "$0")/.."
22apk="${1:-android/app/build/outputs/apk/debug/app-debug.apk}"
23adb="${ADB:-adb}"
24app="${WHISKERS_APP_ID:-app.whiskers}"
25user=()
26[ -z "${WHISKERS_ANDROID_USER:-}" ] || user=(--user "$WHISKERS_ANDROID_USER")
27"$adb" devices -l | tail -n +2 | grep -q . || { echo "no device connected: plug it in and accept the USB debugging prompt" >&2; exit 1; }
28path="$apk"
29if [ -n "${WHISKERS_STAGE_UNIX:-}" ]; then
30  : "${WHISKERS_STAGE_WIN:?set WHISKERS_STAGE_WIN with WHISKERS_STAGE_UNIX}"
31  cp "$apk" "$WHISKERS_STAGE_UNIX"
32  path="$WHISKERS_STAGE_WIN"
33fi
34"$adb" install -r "${user[@]}" "$path"
35"$adb" shell am start "${user[@]}" -n "$app/app.whiskers.MainActivity"