在Eclipse中,有什么方法可以同时在多个模拟器中启动应用程序吗?

发布于 2024-09-27 23:45:56 字数 110 浏览 3 评论 0原文

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

When testing Android layouts, I'm constantly building for three different emulators from Eclipse (with ADT), so I have to run three times and then select each one. Is there any configuration or plugin that allows me to press Run once and the application is started in all three?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潜移默化 2024-10-04 23:45:56

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

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

adb -s install app.apk

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

I wish I had a machine powerful enough to run 3 emulators at once! :)

I doubt the Android Development Tools can do this for you... the nearest you can probably get is to script something. "adb devices" will get you a list of emulator instances, and then you just need to iterate that list running these two command on each :

adb -s <serial-number> install app.apk

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

辞别 2024-10-04 23:45:56

我终于做到了。我使用的是 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。如果应用程序已经存在,adb 会由于 -r 标志而重新安装它。我用 & 连接命令因此每个命令都在后台运行,同时安装和运行。以前我尝试用 && 连接命令,因此每个命令都会等待轮到它,结果是一个慢得多的过程。

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

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

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

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

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

I've finally done it. I'm on a Mac environment so I used Applescript to simplify setting some variables, but this is achievable straight from the terminal.

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

As you can see I'm just running some shell commands. Achieving this specific concatenation of sed's was a pain, but a great learning experience.

The first shell script will install the apk in all the devices found through adb devices. If the app's already there, adb reinstalls it due to the -r flag. I concatenate the commands with & so each command runs in the background, installing and running at the same time. Previously I tried concatenating the commands with &&, so each command waited for its turn and the result was a much slower process.

The second shell script will run the app in all the devices.

I'm sure this can be simplified by someone with greater knowledge of sed, but it works great for me.

Inspired by this little experience, I went ahead and created Automator applications to do this and run adb logcat on each device (so when I ctrl+c out of one logcat, it starts the next one).

I went so far as to create Services to run this Automator apps, however Eclipse in Mac OS X doesn't support Services. The workaround was to run the apps as External Tools.

For extra flavour, I added Growl notifications in my Automator apps to tell me when adb is installing and running the app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文