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
|
#!/bin/bash
EMULATOR_BIN="$ANDROID_HOME/emulator/emulator"
AVD_NAME="Headless_Test"
BASE_PORT="5554"
echo "--- ^=^s Starting Android Emulator '$AVD_NAME' on port $BASE_PORT ---"
if [ ! -f "$EMULATOR_BIN" ]; then
echo " ^}^l Error: Emulator binary not found at $EMULATOR_BIN."
echo " Ensure you installed the 'emulator' package using sdkmanager."
exit 1
fi
if [ ! -d "$HOME/.android/avd/$AVD_NAME.avd" ]; then
echo " ^}^l Error: AVD '$AVD_NAME' not found."
echo " Ensure you created this AVD using avdmanager."
exit 1
fi
"$EMULATOR_BIN" -avd "$AVD_NAME" \
-no-window \
-port "$BASE_PORT" \
-gpu off \
-qemu -monitor none \
-no-snapshot-save &
sleep 2
ADB_PORT=$((BASE_PORT + 1))
EMU_PID=$(jobs -p | tail -1)
echo "--- ^|^e Emulator Started ---"
echo "AVD Name: $AVD_NAME"
echo "Console Port: $BASE_PORT"
echo "ADB Port: $ADB_PORT (Emulator device name: emulator-$ADB_PORT)"
echo "Process ID: $EMU_PID"
echo ""
echo "To connect to this device from your local machine, set up an SSH tunnel:"
echo " ssh -N -L 6001:localhost:$ADB_PORT user@your.server.ip"
echo "Then, connect locally:"
echo " adb connect localhost:6001"
|