I am wondering if there is a way to install and run an android application on multiple devices/emulator with a single click under Eclipse.
When I am testing a layout on
Here is my solution to easily build, install and launch an Android application on multiple devices with exactly two shortcuts STRG+S and STRG+ALT+F10 ;)
1. Build APK
The normal behavior of an Android Build in Eclipse is, that the APK will not be created. But in the preferences is the option to disabled that behavior.
=> After deselecting that option, only a Strg+S is needed to create the APK file after a change in the code.
2. Install and Launch
To install and automatically launch the app for multiple devices, the easiest way is to use the command line and a Windows Batch script in my opinion:
:: This five lines are used to minimize the
:: command lines directly after the start
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
:: Path to the ADB and to the APK file
@set ADB="D:/Android/sdk/platform-tools/adb.exe"
@set APK="D:/workspace_android/SomeApp/bin/SomeApp.apk"
:: AndroidManifest.xml:
:: The launching activity:
@set ACTIVITY=at.example.appname/.activities.HomeActivity
:: Install APK on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: Launch App on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
In my case I have three devices. For faster access to one device, I used the following code instead of the loop in upper code. First, I install and launch the app on the fastest device and after that on the second and so on. I am sure there are better ways instead of using tail, head and xargs, but I don't know that much about Batch files, but it just runs. ;)
:: NEXUS 5
:: This command reinstalls the APK on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: This command launch the application on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
:: Galaxy Tab
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
:: Optimus 3D
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%
After having the Windows Batch script, create a shortcut of that file. Right click the shortcut file and select properties. There you can specify a global shortcut key for example STRG+ALT+F10.
After changing some code in Eclipse, you only have to press STRG+S and then STRG+ALT+F10 and the app will be finally launched on all devices. Yeah! :)