views:

47

answers:

2

When testing Android layouts, I'm constantly building for three different emulators from Eclipse (with ADT), so I have to run three times and then select each one. Is there any configuration or plugin that allows me to press Run once and the application is started in all three?

+2  A: 

I wish I had a machine powerful enough to run 3 emulators at once! :)

I doubt the Android Development Tools can do this for you... the nearest you can probably get is to script something. "adb devices" will get you a list of emulator instances, and then you just need to iterate that list running these two command on each :

adb -s <serial-number> install app.apk

adb -s <serial-number> shell am start -a android.intent.action.MAIN -n org.example.app/org.example.app.MainActivity

Reuben Scratton
Thanks, I've spent the last 3 hours creating an Applescript mixed with some terminal commands and managed to achieve this. I'll post it when I'm finished polishing it.
Solivagant
+1  A: 

I've finally done it. I'm on a Mac environment so I used Applescript to simplify setting some variables, but this is achievable straight from the terminal.

set apkref to "install -r /path/to/your/app.apk"
set appref to "shell am start -a android.intent.action.MAIN -n
com.example.app/com.example.app.MainActivity"
set sourceref to "/path/to/android/tools/"

set devices to do shell script sourceref & "adb devices |  grep \"[device]$\" | 
sed  's/.device/\\ /' | sed  's/^/\\adb -s /' | sed  's@$@\\" & apkref &
" \\&" & "@' | sed  's@^@\\" & sourceref & "@' 
| sed -E -e :a -e '$!N; s/\\n/ /g; ta'"
do shell script devices

set devices to do shell script sourceref & "adb devices |  grep \"[device]$\" | 
sed  's/.device/\\ /' | sed  's/^/\\adb -s /' | sed  's@$@\\" & appref & 
" \\&" & "@' | sed  's@^@\\" & sourceref & "@' 
| sed -E -e :a -e '$!N; s/\\n/ /g; ta'" 
do shell script devices

As you can see I'm just running some shell commands. Achieving this specific concatenation of sed's was a pain, but a great learning experience.

The first shell script will install the apk in all the devices found through adb devices. If the app's already there, adb reinstalls it due to the -r flag. I concatenate the commands with & so each command runs in the background, installing and running at the same time. Previously I tried concatenating the commands with &&, so each command waited for its turn and the result was a much slower process.

The second shell script will run the app in all the devices.

I'm sure this can be simplified by someone with greater knowledge of sed, but it works great for me.

Inspired by this little experience, I went ahead and created Automator applications to do this and run adb logcat on each device (so when I ctrl+c out of one logcat, it starts the next one).

I went so far as to create Services to run this Automator apps, however Eclipse in Mac OS X doesn't support Services. The workaround was to run the apps as External Tools.

For extra flavour, I added Growl notifications in my Automator apps to tell me when adb is installing and running the app.

Solivagant