1#!/usr/bin/env bash 2# Install the debug APK on a connected device and start it. 3# 4# tools/install-android.sh [apk] 5# 6# Environment (all optional): 7# ADB the adb to use (default: adb on PATH). On WSL this may be the Windows adb.exe. 8# ANDROID_SERIAL which device, when several are connected. 9# WHISKERS_ANDROID_USER the Android user to install for (adb --user N), for a tablet with several profiles. 10# WHISKERS_APP_ID the application id (default app.whiskers; match -Pwhiskers.applicationId if you set it). 11# WHISKERS_STAGE_UNIX / WHISKERS_STAGE_WIN 12# a path for the same file as seen from here and as the Windows adb sees it; set both when 13# ADB is a Windows adb.exe that cannot read WSL paths. The APK is copied there first. 14# 15# The app needs no address at build time. A build made with -Pwhiskers.host=<host[:port]> only has it as the DEFAULT; an 16# address a grown-up saved in the app wins, and an app with neither asks for one (parents' side, behind the grown-up lock). 17# 18# `-r` keeps the app's data across updates. The APK is always signed with the committed debug key, so an 19# 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"