Skip to content

Instantly share code, notes, and snippets.

@andaag
Last active April 10, 2016 12:19
Show Gist options
  • Save andaag/9736914 to your computer and use it in GitHub Desktop.
Save andaag/9736914 to your computer and use it in GitHub Desktop.
####### start emulators script:
#!/bin/bash
export PATH=$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools/:$PATH
echo "Android HOME : $ANDROID_HOME"
echo "Android SDK HOME : $ANDROID_SDK_HOME"
echo "PATH : $PATH"
`dirname $0`/kill_android_emulators.sh
function start_emulator() {
echo "Starting emulator $1"
mksdcard 200M sdcard-$1.img
mkdir -p ../../emulator-logs
emulator -avd $1 -show-kernel -verbose -no-window -no-audio -wipe-data -sdcard sdcard-$1.img -qemu >../../emulator-logs/android-emulator-$1.log 2>&1 &
}
function wait_for_device_booted() {
echo "Current boot animation status : $(adb -s $1 shell getprop init.svc.bootanim)"
if [ $(adb -s $1 shell getprop init.svc.bootanim | grep "stopped") ]; then
echo "Boot animation finished"
return
fi
sleep 5
wait_for_device_booted $1
}
for AVD in `ls -1 .android/avd/*ini`; do
AVD=$(basename ${AVD} | sed 's:\.ini::g')
start_emulator $AVD
done
echo "Waiting for initial emulator start"
adb -e wait-for-devices &>/dev/null
DEVICES=$(adb devices | grep -v 'List of devices' | cut -f 1 | xargs echo)
IFS=' '
for DEVICE in $DEVICES; do
echo "Waiting for $DEVICE"
adb -s $DEVICE wait-for-device
wait_for_device_booted $DEVICE
done
`dirname $0`/setup_devices_for_test.sh "$1"
echo "Boot completed, ready to test on:"
adb devices
sleep 10
### Kill emulators script (run before and after launch):
#!/bin/bash
export PATH=$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools/:$PATH
DEVICES=$(adb devices | grep -v 'List of devices' | cut -f 1 | xargs echo)
IFS=' '
for DEVICE in $DEVICES; do
adb -s $DEVICE emu kill &>/dev/null && sleep 2
done
pkill -f 'sdk.*/tools.*/emulator.*avd.*no-window.*qemu' && sleep 10
pkill -9 -f 'sdk.*/tools.*/emulator.*avd.*no-window.*qemu' && sleep 1
adb kill-server
rm -rf /tmp/android-*/emulator-* &>/dev/null
rm -rf /tmp/android-*/qemu-* &>/dev/null
exit 0
@andaag
Copy link
Author

andaag commented Mar 24, 2014

Run before and after the builds:

!/bin/bash

export PATH=$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools/:$PATH
DEVICES=$(adb devices | grep -v 'List of devices' | cut -f 1 | xargs echo)
IFS=' '
for DEVICE in $DEVICES; do
adb -s $DEVICE emu kill &>/dev/null && sleep 2
done
pkill -f 'sdk./tools./emulator.avd.no-window.qemu' && sleep 10
pkill -9 -f 'sdk.
/tools.
/emulator.avd.no-window.qemu' && sleep 1
adb kill-server
rm -rf /tmp/android-
/emulator-
&>/dev/null
rm -rf /tmp/android-
/qemu-
&>/dev/null
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment