Android gradle 插件如何 select 所有设备?

How does the Android gradle plugin select all devices?

我正在编写一个小的 gradle 插件,我需要在其中使用 adb 命令。我的问题是 installDebug 任务如何知道所有设备?默认情况下,它将安装在所有设备上。我找到了 installTask 但没有 -s 用于指定设备的参数。

他们是如何在 Android gradle plugin 中做到这一点的?

额外问题:在 Android Studio 中我可以 select 一个特殊的设备,我如何从 gradle 脚本中知道?

InstallTask 没有出现在最新的资源中。 InstallVariantTask is used instead of it. As you can see from its sources it checks ANDROID_SERIAL environment variable for specific device selection and if the variable is not present then the install task is run against all compatible devices (the same is done for uninstall and connectedAndroidTest 个任务)。

奖励答案:据我所知这是不可能的。 Android Studio does not install/launch 通过 gradle 应用程序。在 .idea/workspace.xml 文件中,您会找到 ANDROID_EXTENDED_DEVICE_CHOOSER_SERIALS 属性,它会在您的 APK 部署后的某个时间点更新,但此信息在 gradle 脚本期间不可用运行.