-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathdevtools
More file actions
executable file
·192 lines (153 loc) · 4.99 KB
/
Copy pathdevtools
File metadata and controls
executable file
·192 lines (153 loc) · 4.99 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
set -euo pipefail
print_usage() {
cat <<EOF
devtools — manage the BTC Map Android dev environment.
Usage:
./devtools emulator start Boot the AVD asynchronously
./devtools emulator stop Shut the emulator down cleanly
./devtools app install Install debug build
./devtools app run Install and run debug build
./devtools app uninstall Uninstall the app
./devtools app deploy-beta Build and deploy beta APK
./devtools app deploy-release Build and deploy release APK
EOF
}
print_usage_emulator() {
cat <<EOF
Usage: ./devtools emulator <command>
Commands:
start Boot the AVD asynchronously
stop Shut the emulator down cleanly
EOF
}
print_usage_app() {
cat <<EOF
Usage: ./devtools emulator <command>
Commands:
install Install debug build
run Install and run debug build
uninstall Uninstall the app
deploy-beta Build and deploy beta APK
deploy-release Build and deploy release APK
EOF
}
# START emulator section
cmd_emulator_start() {
# Detach from the shell so the script can exit cleanly while the
# emulator keeps running.
nohup setsid emulator -avd Resizable_Experimental -gpu host > emulator.log 2>&1 < /dev/null & disown
}
cmd_emulator_stop() {
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
rm emulator.log
}
cmd_emulator() {
local sub="${1:-help}"
shift || true
case "$sub" in
start) cmd_emulator_start ;;
stop) cmd_emulator_stop ;;
help|-h|--help) print_usage_emulator ;;
*) err "Unknown emulator command: $sub"; print_usage_emulator; return 1 ;;
esac
}
# END emulator section
# START app section
cmd_app_install() {
local device="emulator-5554"
local apk_path="./app/build/outputs/apk/debug/app-x86_64-debug.apk"
if ! adb devices | grep -q "^$device[[:space:]]"; then
echo "Error: emulator $device is not running. Start it with: ./devtools emulator start" >&2
return 1
fi
echo "Assembling debug APK..."
./gradlew assembleDebug "$@"
if [ ! -f "$apk_path" ]; then
echo "Error: APK not found at $apk_path" >&2
return 1
fi
echo "Installing $apk_path on $device..."
adb -s "$device" install -r -t "$apk_path"
}
cmd_app_run() {
local device="emulator-5554"
local package="org.btcmap.debug"
local apk_path="./app/build/outputs/apk/debug/app-x86_64-debug.apk"
if ! adb devices | grep -q "^$device[[:space:]]"; then
echo "Error: emulator $device is not running. Start it with: ./devtools emulator start" >&2
return 1
fi
echo "Assembling debug APK..."
./gradlew assembleDebug "$@"
if [ ! -f "$apk_path" ]; then
echo "Error: APK not found at $apk_path" >&2
return 1
fi
echo "Installing $apk_path on $device..."
adb -s "$device" install -r -t "$apk_path"
echo "Launching $package..."
adb -s "$device" shell monkey -p "$package" -c android.intent.category.LAUNCHER 1
echo "Process status:"
adb -s "$device" shell ps -A | grep btcmap || echo "(process not visible yet — give it a moment)"
}
cmd_app_uninstall() {
local device="emulator-5554"
local package="org.btcmap.debug"
if ! adb devices | grep -q "^$device[[:space:]]"; then
echo "Error: emulator $device is not running. Start it with: ./devtools emulator start" >&2
return 1
fi
if ! adb -s "$device" shell pm list packages "$package" 2>/dev/null \
| tr -d '\r' | grep -qx "package:$package"; then
echo "$package is not installed on $device. Nothing to do."
return 0
fi
echo "Uninstalling $package from $device..."
local result
if result=$(adb -s "$device" uninstall "$package" 2>&1); then
echo "$result"
else
echo "Uninstall failed: $result" >&2
return 1
fi
}
cmd_app_deploy_beta() {
./gradlew assembleBeta "$@"
local apk_dir="app/build/outputs/apk/beta"
local dest="btcmap-api:/srv/http/static.btcmap.org/android/apk/"
rsync -avz --progress "$apk_dir"/btcmap-*-arm.apk "$dest/beta.apk"
rsync -avz --progress "$apk_dir"/btcmap-*-universal.apk "$dest/beta-universal.apk"
}
cmd_app_deploy_release() {
./gradlew assembleRelease "$@"
local apk_dir="app/build/outputs/apk/release"
local dest="btcmap-api:/srv/http/static.btcmap.org/android/apk/"
rsync -avz --progress "$apk_dir"/btcmap-*-arm.apk "$dest/release.apk"
rsync -avz --progress "$apk_dir"/btcmap-*-universal.apk "$dest/release-universal.apk"
}
cmd_app() {
local target="${1:-help}"
shift || true
case "$target" in
install) cmd_app_install "$@" ;;
run) cmd_app_run "$@" ;;
uninstall) cmd_app_uninstall "$@" ;;
deploy-beta) cmd_app_deploy_beta "$@" ;;
deploy-release) cmd_app_deploy_release "$@" ;;
help|-h|--help) print_usage_app ;;
*) err "Unknown app command: $target"; print_usage_app; return 1 ;;
esac
}
# END app section
main() {
local cmd="${1:-help}"
shift || true
case "$cmd" in
emulator) cmd_emulator "$@" ;;
app) cmd_app "$@" ;;
help|-h|--help) print_usage ;;
*) err "Unknown command: $cmd"; print_usage; return 1 ;;
esac
}
main "$@"