Multi-device deployment with IntelliJ/Android Studio

If you’re just back from a hike in the Tibetan mountains, you might have missed the fact that Google announced Android Studio during the keynote at I/O. It’s nice to see that Google, too, appreciates the quality of JetBrains’ work. Personally, I’ve been using IntelliJ at work for a few weeks now and I would never look back to the mess that is Eclipse + ADT.

However, said mess does have a single feature that I use daily - deploying an app to multiple devices simultaneously. This is a setting in the Eclipse Run configurations but unfortunately the IDEA counterpart only has two options - emulator or USB device.

Shell scripts to the rescue!

Here is a simple script (Linux only, requires GNU parallel, inotify-utils) that will automatically pick up the changed apk from bin/classes/{NAME_GOES_HERE}.apk, install it on all connected devices and then launch the optional activity (specified as the first argument to the script). If you don’t have GNU parallel, you can replace its usage with a for loop, at the expense of some speed.

Once you start it (from the right place, the root of your project), just do “Make Project” in IDEA and the script will pick up the closing write (inotifywait is magic!) and upload the apk.

I hope it’s useful to someone.

← Android's matryoshka problem An improved sliding pane for Android_→