#!/bin/sh # Build the app and install it on the connected device/emulator. # Usage: sh tools/build_and_deploy.sh set -e cd "$(dirname "$0")/.." . ./android_env.sh # Pick a target when several devices are connected (gradle and adb both honor # ANDROID_SERIAL). Prefers the physical device; set ANDROID_SERIAL to override. if [ -z "$ANDROID_SERIAL" ]; then devices=$(adb devices | awk 'NR>1 && $2=="device" {print $1}') count=$(printf '%s\n' "$devices" | grep -c . || true) if [ "$count" -gt 1 ]; then physical=$(printf '%s\n' "$devices" | grep -v '^emulator-' || true) if [ "$(printf '%s\n' "$physical" | grep -c . || true)" -eq 1 ]; then ANDROID_SERIAL=$physical export ANDROID_SERIAL echo "Multiple devices connected; targeting $ANDROID_SERIAL (set ANDROID_SERIAL to override)." else echo "Multiple devices connected; set ANDROID_SERIAL to pick one:" adb devices exit 1 fi fi fi echo "=== Building ===" ./gradlew assembleDebug 2>&1 | tail -5 echo "" echo "=== Installing ===" ./gradlew installDebug 2>&1 | tail -5 echo "" echo "=== Launching ===" adb shell am start -n dev.azom.privacypin/.MainActivity echo "" echo "Done. App launched on device."