Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple deploy via Maven to Android devices on a USB Hub

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?

like image 734
Mo Kargas Avatar asked Aug 28 '12 23:08

Mo Kargas


2 Answers

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.

like image 95
yorkw Avatar answered Nov 11 '22 00:11

yorkw


As yorkow correctly mentions the Android Maven Plugin supports multiple connected devices and emulators.

In fact it does so either for all attached devices and emulators (no parameter), all attached devices (device parameter set to usb), all emulators (device parameter set to emulator) or a specific devices (device parameter set to serial number of the device).

In order to use the plugin I would suggest to look at the Android Maven Plugin website as well as the chapter about Android development with it in the book Maven: The Complete Reference

The main thing to keep in mind is that this parameter and the multi device support applies for all device interaction goals (deploy, undeploy, redeploy, run, instrument, pull and push) so you can e.g. run all tests on a number of devices or push files to all attached devices as well.

Also depending on the operating system you will need to add the USB manufacturer identification to the udev rules or other setup. See more on the dev site.

Try

adb devices 

first and then use the Android Maven Plugin goal to see what it can detect with

mvn android:devices

PS: I am core committer on the plugin and author of the linked book content..

like image 1
Manfred Moser Avatar answered Nov 11 '22 01:11

Manfred Moser