3# Build the debug APK, then install and launch the app on a physically
4# connected device (USB or wireless). Unlike scripts/run.sh, this never boots
5# an emulator — it targets real hardware only.
8# scripts/run-device.sh # build + install + launch on the connected device
9# scripts/run-device.sh -s <serial> # target a specific device (see `adb devices`)
10# scripts/run-device.sh -c 192.168.1.5 # adb connect over Wi-Fi first (host or host:port)
11# scripts/run-device.sh --no-build # skip the Gradle build, just install + launch
12# scripts/run-device.sh --release # build/install the release variant
16APP_ID="soy.iko.opencode"
17ACTIVITY=".MainActivity"
23while [[ $# -gt 0 ]]; do
25 -s|--serial) SERIAL="$2"; shift 2 ;;
26 -c|--connect) CONNECT="$2"; shift 2 ;;
27 --no-build) DO_BUILD=0; shift ;;
28 --release) VARIANT="release"; shift ;;
30 awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"
32 *) echo "Unknown argument: $1" >&2; exit 2 ;;
36cd "$(dirname "$0")/.."
38# --- locate adb -------------------------------------------------------------
39SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}"
42 if command -v "$name" >/dev/null 2>&1; then command -v "$name"; return; fi
43 for d in "$SDK/platform-tools" "$SDK/cmdline-tools/latest/bin"; do
44 [[ -x "$d/$name" ]] && { echo "$d/$name"; return; }
49[[ -z "$ADB" ]] && { echo "error: 'adb' not found; set ANDROID_HOME / ANDROID_SDK_ROOT" >&2; exit 1; }
51# --- optional wireless connect ---------------------------------------------
52if [[ -n "$CONNECT" ]]; then
53 [[ "$CONNECT" == *:* ]] || CONNECT="$CONNECT:5555"
54 echo ">> Connecting to $CONNECT..."
55 "$ADB" connect "$CONNECT"
56 SERIAL="${SERIAL:-$CONNECT}"
59# --- pick a physical device (exclude emulators) -----------------------------
60# Lists serials of connected, ready devices whose serial is NOT emulator-*.
62 "$ADB" devices | awk 'NR>1 && $2=="device" && $1 !~ /^emulator-/ {print $1}'
65if [[ -z "$SERIAL" ]]; then
67 while IFS= read -r line; do [[ -n "$line" ]] && DEVICES+=("$line"); done < <(physical_devices)
68 case "${#DEVICES[@]}" in
69 0) echo "error: no physical device connected (enable USB debugging, or use -c for Wi-Fi)" >&2; exit 1 ;;
70 1) SERIAL="${DEVICES[0]}" ;;
71 *) echo "error: multiple devices connected; choose one with -s <serial>:" >&2
72 printf ' %s\n' "${DEVICES[@]}" >&2
76echo ">> Target device: $SERIAL"
78# Confirm the chosen device is actually ready.
79if ! "$ADB" -s "$SERIAL" get-state 2>/dev/null | grep -q '^device$'; then
80 echo "error: device '$SERIAL' is not ready (unauthorized or offline?)" >&2
84# --- build ------------------------------------------------------------------
85if [[ "$VARIANT" == "release" ]]; then
86 GRADLE_TASK="assembleRelease"
87 APK="app/build/outputs/apk/release/app-release.apk"
89 GRADLE_TASK="assembleDebug"
90 APK="app/build/outputs/apk/debug/app-debug.apk"
93if [[ "$DO_BUILD" -eq 1 ]]; then
94 echo ">> Building ($GRADLE_TASK)..."
95 ./gradlew "$GRADLE_TASK"
97[[ -f "$APK" ]] || { echo "error: APK not found at $APK (did the build run?)" >&2; exit 1; }
99# --- install + launch -------------------------------------------------------
100echo ">> Installing $APK on $SERIAL..."
101"$ADB" -s "$SERIAL" install -r "$APK"
103echo ">> Launching $APP_ID/$ACTIVITY..."
104"$ADB" -s "$SERIAL" shell am start -n "$APP_ID/$ACTIVITY"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list