-
Notifications
You must be signed in to change notification settings - Fork 379
Expand file tree
/
Copy pathrun-android.sh
More file actions
executable file
·40 lines (35 loc) · 975 Bytes
/
run-android.sh
File metadata and controls
executable file
·40 lines (35 loc) · 975 Bytes
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
# DON'T RUN THIS FILE DIRECTLY, USE PACKAGE.JSON SCRIPTS
#!/bin/bash
set -e
serials=$(adb devices | awk '/\tdevice$/{print $1}')
if [ -z "$serials" ]; then
echo "No Android devices connected. Start an emulator and try again."
exit 1
fi
labels=()
devices=()
while IFS= read -r serial; do
avd=$(adb -s "$serial" emu avd name 2>/dev/null | head -1 | tr -d '\r')
label="${avd:-$serial} ($serial)"
labels+=("$label")
devices+=("$serial")
done <<< "$serials"
if [ ${#devices[@]} -eq 1 ]; then
selected="${devices[0]}"
echo "Using device: ${labels[0]}"
else
echo "Select a device:"
for i in "${!labels[@]}"; do
echo " $((i+1))) ${labels[$i]}"
done
printf "Choice [1]: "
read -r choice
choice=${choice:-1}
idx=$((choice - 1))
if [ "$idx" -lt 0 ] || [ "$idx" -ge ${#devices[@]} ]; then
echo "Invalid choice."
exit 1
fi
selected="${devices[$idx]}"
fi
ANDROID_SERIAL="$selected" bunx react-native run-android --deviceId "$selected"