GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode-mobile/run-android.sh at main · opencode-mobile/opencode-mobile

Expand file tree

/

run-android.sh

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
167 lines (143 loc) · 3.84 KB
/

run-android.sh

Copy path

File metadata and controls

executable file
·
167 lines (143 loc) · 3.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ANDROID_DIR="$ROOT_DIR/android"
APP_ID="${ANDROID_APP_ID:-dev.opencode.mobile}"
ADB="${ADB:-adb}"
VERBOSE=0
usage() {
cat <<EOF
Usage: ./run-android.sh [-v|--v|--verbose]
Build, install, and launch $APP_ID on a connected device or emulator.
Options:
-v, --v, --verbose Print full command output
EOF
}
for arg in "$@"; do
case "$arg" in
-v|--v|--verbose)
VERBOSE=1
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $arg" >&2
usage >&2
exit 1
;;
esac
done
run_quiet() {
local label="$1"
shift
if [[ "$VERBOSE" -eq 1 ]]; then
"$@"
return
fi
local log
log="$(mktemp -t "opencode-run-android.${label}.XXXXXX")"
local status=0
"$@" >"$log" 2>&1 || status=$?
if [[ "$status" -eq 0 ]]; then
rm -f "$log"
return 0
fi
echo "error: $label failed (exit $status)" >&2
tail -n 50 "$log" >&2 || true
echo "Full log: $log (re-run with --v for live output)" >&2
exit "$status"
}
if [[ ! -x "$ANDROID_DIR/gradlew" ]]; then
echo "error: Missing Android Gradle wrapper at $ANDROID_DIR/gradlew" >&2
exit 1
fi
resolve_android_sdk() {
if [[ -n "${ANDROID_HOME:-}" && -d "$ANDROID_HOME" ]]; then
echo "$ANDROID_HOME"
elif [[ -n "${ANDROID_SDK_ROOT:-}" && -d "$ANDROID_SDK_ROOT" ]]; then
echo "$ANDROID_SDK_ROOT"
elif [[ -d "$HOME/Library/Android/sdk" ]]; then
echo "$HOME/Library/Android/sdk"
fi
}
SDK="$(resolve_android_sdk)"
if ! command -v "$ADB" >/dev/null 2>&1; then
if [[ -n "$SDK" && -x "$SDK/platform-tools/adb" ]]; then
ADB="$SDK/platform-tools/adb"
else
echo "error: adb was not found. Install Android platform-tools or set ADB." >&2
exit 1
fi
fi
EMULATOR="${EMULATOR:-}"
if [[ -z "$EMULATOR" && -n "$SDK" && -x "$SDK/emulator/emulator" ]]; then
EMULATOR="$SDK/emulator/emulator"
fi
find_physical_device() {
"$ADB" devices | awk '$1 !~ /^emulator-/ && $2 == "device" { print $1; exit }'
}
find_running_emulator() {
"$ADB" devices | awk '$1 ~ /^emulator-/ && $2 == "device" { print $1; exit }'
}
wait_for_emulator_boot() {
local device="$1"
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Waiting for $device to finish booting..."
fi
"$ADB" -s "$device" wait-for-device
until [[ "$("$ADB" -s "$device" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" == "1" ]]; do
sleep 1
done
}
pick_avd() {
if [[ -z "$EMULATOR" ]]; then
echo "error: emulator was not found. Install the Android Emulator or set EMULATOR." >&2
exit 1
fi
local avds
avds="$("$EMULATOR" -list-avds)"
if [[ -z "$avds" ]]; then
echo "error: No Android Virtual Devices found. Create one in Android Studio." >&2
exit 1
fi
if [[ -n "${ANDROID_AVD:-}" ]]; then
if echo "$avds" | grep -Fxq "$ANDROID_AVD"; then
echo "$ANDROID_AVD"
return
fi
echo "error: No AVD named '${ANDROID_AVD}'." >&2
exit 1
fi
echo "$avds" | head -n 1
}
start_emulator() {
local avd="$1"
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Starting Android emulator: $avd"
fi
"$EMULATOR" -avd "$avd" -no-boot-anim >/dev/null 2>&1 &
}
if [[ -n "${ANDROID_SERIAL:-}" ]]; then
DEVICE="$ANDROID_SERIAL"
else
DEVICE="$(find_physical_device)"
if [[ -z "${DEVICE:-}" ]]; then
DEVICE="$(find_running_emulator)"
fi
fi
if [[ -z "${DEVICE:-}" ]]; then
AVD="$(pick_avd)"
start_emulator "$AVD"
"$ADB" wait-for-device
DEVICE="$(find_running_emulator)"
if [[ -z "${DEVICE:-}" ]]; then
echo "error: Emulator started but no device serial was detected." >&2
exit 1
fi
wait_for_emulator_boot "$DEVICE"
fi
run_quiet install "$ANDROID_DIR/gradlew" -p "$ANDROID_DIR" :app:installDebug
run_quiet launch "$ADB" -s "$DEVICE" shell monkey -p "$APP_ID" -c android.intent.category.LAUNCHER 1
echo "success: Launched $APP_ID on $DEVICE."
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.