Files

34 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Build and install onto a connected device.
#
# Wireless debugging uses two different ports: one for the one-time pairing and
# another, shown on the Wireless debugging screen itself, for the connection.
# Mixing them up is the usual reason `adb pair` appears to work but no device
# shows up afterwards.
#
# ./deploy.sh build and install to whatever is attached
# ./deploy.sh pair 10.0.0.9:37000 123456 one time, per device
# ./deploy.sh connect 10.0.0.9:5555 after a phone reboot
set -eu
: "${ANDROID_HOME:=$HOME/Android/Sdk}"
ADB="$ANDROID_HOME/platform-tools/adb"
HERE=$(cd "$(dirname "$0")" && pwd)
case "${1:-install}" in
pair) exec "$ADB" pair "$2" "$3" ;;
connect) exec "$ADB" connect "$2" ;;
logcat) exec "$ADB" logcat --pid="$("$ADB" shell pidof com.example.todo)" ;;
esac
if [ -z "$("$ADB" devices | sed '1d' | grep -v '^$' || true)" ]; then
echo "no device. pair or connect first, see the top of this script" >&2
exit 1
fi
cd "$HERE"
./gradlew --quiet assembleDebug
"$ADB" install -r app/build/outputs/apk/debug/app-debug.apk
echo "installed. launching."
"$ADB" shell monkey -p com.example.todo -c android.intent.category.LAUNCHER 1 >/dev/null