Multiple deploy via Maven to Android devices on a USB Hub

android, ddms, maven

Solution

The current version of Android SDK does not support install apk on multiple connected devices at once. This is the hard limitation, so the only workaround at the moment is to iterate the attached devices and issue the install command for each of them.

If you look at the android-maven-plugin documentation, you can see there is an interesting parameter in android:deploy goal that you can specify in pom.xml:

device:

Specifies which device to connect to, by serial number. Special values "usb" and "emulator" are also valid, for selecting the only USB connected device or the only running emulator, respectively.

- Type: java.lang.String

- Required: No

- Expression: ${android.device}

Well, the documentation claims that it will install apk to the only connected device. I have tested it myself, it also work if multiple devices are connected.

Sample pom.xml:

<plugin>
  <groupId>com.jayway.maven.plugins.android.generation2</groupId>
  <artifactId>android-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <sdk>
      <platform>13</platform>
    </sdk>
    <undeployBeforeDeploy>true</undeployBeforeDeploy>
    <!-- Install apk to multiple attached devices -->
    <device>usb</device>
   </configuration>
</plugin>

Sample log by running `mvn android:deploy`:

[INFO] Waiting for initial device list from the Android Debug Bridge
[INFO] Found 2 devices connected with the Android Debug Bridge
[INFO] android.device parameter set to usb
[INFO] Device 0123456789abcd_samsung_GT-I9100 found.
[INFO] Successfully uninstalled com.company.app from 0123456789abcd_samsung_GT-I9100
[INFO] Device 0123456789efg_HTC_HTCDesire found.
[INFO] Successfully uninstalled com.company.app from 0123456789efg_HTC_HTCDesire
[INFO] Found 2 devices connected with the Android Debug Bridge
[INFO] android.device parameter set to usb
[INFO] Device 0123456789abcd_samsung_GT-I9100 found.
[INFO] Successfully installed C:\workspace\my-app\target\app-1.0.0-SNAPSHOT.apk to 0123456789abcd_samsung_GT-I9100
[INFO] Device 0123456789efg_HTC_HTCDesire found.
[INFO] Successfully installed C:\workspace\my-app\target\app-1.0.0-SNAPSHOT.apk to 0123456789efg_HTC_HTCDesire
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

If you want to know how android-maven-plugin implement it, check out source code here.

Problem

I've searched on SO for a while on this but cannot find a definitive answer. I've recently purchased a 7 port USB Hub for my dev machine, with 7 differing Android devices on it. This was done primarily to keep everything all charged, but I am also trying to find out if it possible to configure Maven or even DDMS) to recognize the devices and deploy to all of them at once through the hub?

Original source