当前版本的Android SDK不支持同时在多个连接的设备上安装apk.这是一个硬性限制,因此目前唯一的解决方法是迭代连接的设备并为每个设备发出安装命令.
如果你看一下android-maven-plugin documentation,你可以看到android中有一个有趣的参数:你可以在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}
好吧,该文档声称它将安装apk到唯一连接的设备.我自己测试了它,如果连接了多个设备,它也可以工作.
示例pom.xml:
com.jayway.maven.plugins.android.generation2
android-maven-plugin
true
13
true
usb
通过运行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] ------------------------------------------------------------------------
如果你想知道android-maven-plugin如何实现它,请查看source code here.