#!/usr/bin/env bash # Run in Ubuntu WSL after: usbipd attach --wsl --busid (Windows Admin PowerShell) set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" APK="$ROOT/app/build/outputs/apk/debug/app-debug.apk" export PATH="${HOME}/Android/Sdk/platform-tools:${PATH}" export ADB_INSTALL_TIMEOUT="${ADB_INSTALL_TIMEOUT:-3600}" echo "=== lsusb (expect Samsung / 04e8) ===" lsusb || true adb kill-server || true sleep 1 echo "=== adb devices ===" adb devices WAIT_MAX="${WAIT_FOR_DEVICE_SECS:-180}" elapsed=0 while ! adb devices 2>/dev/null | grep -q $'\tdevice$'; do if adb devices 2>/dev/null | grep -q $'\tunauthorized$'; then echo "Unauthorized — unlock the phone and tap Allow on the USB debugging (RSA) prompt..." else echo "No device — run usbipd attach (Windows), check cable/USB mode..." fi if (( elapsed >= WAIT_MAX )); then echo "Timed out after ${WAIT_MAX}s waiting for device." >&2 adb devices exit 1 fi sleep 5 elapsed=$((elapsed + 5)) # After you tap Allow, reconnecting ADB often flips unauthorized → device. adb kill-server 2>/dev/null || true sleep 1 done echo "=== adb devices (ready) ===" adb devices cd "$ROOT" if [[ ! -f "$APK" ]]; then echo "=== building debug APK ===" ./gradlew :app:assembleDebug --no-daemon fi echo "=== adb install (large APK over usbip can take many minutes) ===" # --streaming avoids a separate full-file sync that often EOFs over USB/IP. if ! adb install -r -d --streaming "$APK"; then echo "Streaming install failed; retrying without --streaming..." >&2 adb install -r -d "$APK" fi echo "=== verify ===" adb shell pm path com.smoa echo "Done."