3# Build the debug APK, make sure an emulator is running, then install and launch
7# scripts/run.sh # build + install + launch on an emulator
8# scripts/run.sh -a Pixel_7 # boot a specific AVD if none is running
9# scripts/run.sh --no-build # skip the Gradle build, just install + launch
10# scripts/run.sh --release # build/install the release variant
14APP_ID="soy.iko.opencode"
15ACTIVITY=".MainActivity"
20while [[ $# -gt 0 ]]; do
22 -a|--avd) AVD="$2"; shift 2 ;;
23 --no-build) DO_BUILD=0; shift ;;
24 --release) VARIANT="release"; shift ;;
26 awk 'NR>1 && /^#/ {sub(/^# ?/,""); print; next} NR>1 {exit}' "$0"
28 *) echo "Unknown argument: $1" >&2; exit 2 ;;
32cd "$(dirname "$0")/.."
34# --- locate the Android SDK tools ------------------------------------------
35SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}"
38 if command -v "$name" >/dev/null 2>&1; then command -v "$name"; return; fi
39 for d in "$SDK/platform-tools" "$SDK/emulator" "$SDK/cmdline-tools/latest/bin"; do
40 [[ -x "$d/$name" ]] && { echo "$d/$name"; return; }
45EMULATOR="$(find_tool emulator)"
46[[ -z "$ADB" ]] && { echo "error: 'adb' not found; set ANDROID_HOME / ANDROID_SDK_ROOT" >&2; exit 1; }
48# --- ensure an emulator/device is connected --------------------------------
50 "$ADB" devices | awk 'NR>1 && $2=="device" {found=1} END {exit found?0:1}'
53if ! device_ready; then
54 echo ">> No running device/emulator; booting one..."
55 [[ -z "$EMULATOR" ]] && { echo "error: 'emulator' not found; start a device manually" >&2; exit 1; }
57 if [[ -z "$AVD" ]]; then
58 AVD="$("$EMULATOR" -list-avds | head -n1)"
59 [[ -z "$AVD" ]] && { echo "error: no AVDs found; create one in Android Studio or pass -a <name>" >&2; exit 1; }
61 echo ">> Starting AVD: $AVD"
62 "$EMULATOR" -avd "$AVD" -netdelay none -netspeed full >/dev/null 2>&1 &
64 echo ">> Waiting for device..."
65 "$ADB" wait-for-device
66 # Wait until the OS has finished booting.
67 until [[ "$("$ADB" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" == "1" ]]; do
70 echo ">> Emulator booted."
73# --- build ------------------------------------------------------------------
74if [[ "$VARIANT" == "release" ]]; then
75 GRADLE_TASK="assembleRelease"
76 APK="app/build/outputs/apk/release/app-release.apk"
78 GRADLE_TASK="assembleDebug"
79 APK="app/build/outputs/apk/debug/app-debug.apk"
82if [[ "$DO_BUILD" -eq 1 ]]; then
83 echo ">> Building ($GRADLE_TASK)..."
84 ./gradlew "$GRADLE_TASK"
86[[ -f "$APK" ]] || { echo "error: APK not found at $APK (did the build run?)" >&2; exit 1; }
88# --- install + launch -------------------------------------------------------
89echo ">> Installing $APK..."
90"$ADB" install -r "$APK"
92echo ">> Launching $APP_ID/$ACTIVITY..."
93"$ADB" 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