2

在测试 Android 布局时,我不断地从 Eclipse(使用 ADT)构建三个不同的模拟器,所以我必须运行 3 次,然后选择每一个。是否有任何配置或插件允许我按一次运行并在所有三个中启动应用程序?

4

2 回答 2

2

我希望我有一台足够强大的机器,可以同时运行 3 个模拟器!:)

我怀疑Android开发工具可以为你做这件事......你可能得到的最接近的是编写一些东西。“adb devices”将为您提供一个模拟器实例列表,然后您只需要迭代该列表,在每个列表上运行这两个命令:

adb -s <序列号>安装 app.apk

adb -s <序列号> shell am start -a android.intent.action.MAIN -n org.example.app/org.example.app.MainActivity

于 2010-10-19T15:02:42.460 回答
2

我终于做到了。我在 Mac 环境中,所以我使用 Applescript 来简化一些变量的设置,但这可以直接从终端实现。

set apkref to "install -r /path/to/your/app.apk"
set appref to "shell am start -a android.intent.action.MAIN -n
com.example.app/com.example.app.MainActivity"
set sourceref to "/path/to/android/tools/"

set devices to do shell script sourceref & "adb devices |  grep \"[device]$\" | 
sed  's/.device/\\ /' | sed  's/^/\\adb -s /' | sed  's@$@\\" & apkref &
" \\&" & "@' | sed  's@^@\\" & sourceref & "@' 
| sed -E -e :a -e '$!N; s/\\n/ /g; ta'"
do shell script devices

set devices to do shell script sourceref & "adb devices |  grep \"[device]$\" | 
sed  's/.device/\\ /' | sed  's/^/\\adb -s /' | sed  's@$@\\" & appref & 
" \\&" & "@' | sed  's@^@\\" & sourceref & "@' 
| sed -E -e :a -e '$!N; s/\\n/ /g; ta'" 
do shell script devices

如您所见,我只是在运行一些 shell 命令。实现 sed 的这种特定连接是一种痛苦,但却是一次很棒的学习经历。

第一个 shell 脚本将在通过 adb devices 找到的所有设备中安装 apk。如果应用程序已经存在,由于 -r 标志,adb 会重新安装它。我用 & 连接命令,所以每个命令都在后台运行,同时安装和运行。以前我尝试用 && 连接命令,所以每个命令都等待轮到它,结果是一个慢得多的过程。

第二个 shell 脚本将在所有设备上运行该应用程序。

我确信这可以由对 sed 有更多了解的人来简化,但这对我来说非常有用。

受到这个小小的经验的启发,我继续创建 Automator 应用程序来执行此操作并在每台设备上运行 adb logcat(所以当我从一个 logcat 中按 ctrl+c 时,它会启动下一个 logcat)。

我什至创建了服务来运行这个 Automator 应用程序,但是 Mac OS X 中的 Eclipse 不支持服务。解决方法是将应用程序作为外部工具运行。

为了增加风味,我在我的 Automator 应用程序中添加了 Growl 通知,以告诉我 adb 何时安装和运行应用程序。

于 2010-10-20T10:30:02.307 回答