在 Eclipse 下单击一下即可在多个设备上安装并运行应用程序
我想知道是否有一种方法可以在 Eclipse 下单击一下在多个设备/模拟器上安装和运行 Android 应用程序。
当我在多个 (n) 设备上测试布局时,我现在正在执行 n 次 run-as(实际上是 ctrl-F11 快捷键),选择正确的设备,然后检查每个设备上的布局。
如果能够使用单个命令在连接到我的计算机的所有设备上进行安装和启动,那就太棒了。
这样的事情存在吗?
I am wondering if there is a way to install and run an android application on multiple devices/emulator with a single click under Eclipse.
When I am testing a layout on multiple (n) devices I am doing right now n times run-as (ctrl-F11 short cut in fact), choose the correct device and then check my layout on each device.
It would be great to use a single command to install and launch on all devices connected to my computer.
Does a such thing exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用 Eclipse,只需执行以下操作:
应弹出另一个对话框,选择“目标”选项卡,选择“在所有兼容设备/AVD 上启动”。
应用,您应该在运行/调试时安装所有设备。
If you using eclipse, just do below:
another dialog should pop up, select 'target' tab, select 'Launch on all compatible devics/AVD's '.
Apply and you should get all of devices install when Run/Debug.
最简单的方法是使用包含几行的批处理文件(或 shell 脚本)
确保 Eclipse 设置为自动构建项目。然后,它不是一键单击,而是关闭:
The simplest way is to have a batch file (or shell script) with several lines
Make sure that Eclipse is set to build the project automatically. Then, it's not one-click, but close:
我刚刚完成了 Aleadam 建议我做的脚本。
连接到计算机的每个设备上的一个简单循环,进行安装和启动。
脚本和安装:
使用示例:
I just finished the script Aleadam advice me to do.
A simple loop on each device connected to the computer with install and start.
Script andinstall:
Usage example:
您应该能够将 Ant XML 文件添加到 Eclipse 项目中,并使用可以从命令行运行外部程序的 Ant 任务填充它。也许您应该为要运行的每个设备拥有一个单独的任务项,然后包含所有这些设备的父任务。
然后向 Eclipse 项目添加一个自定义构建器步骤,选择 Ant 作为构建器并指向之前添加的 XML 文件(请参阅 此处)
我不是 Ant 方面的专家,但在某些时候我需要添加一个自定义任务从 Eclipse 中从我的项目代码构建一个 Jar,以便我可以在每次需要时运行它(例如 此处)。这个过程非常有效。
应该为您执行的 Ant 任务是 Exec: http://ant.apache.org /manual/Tasks/exec.html。您可能想查看http://ant.apache.org/manual/using。 html 作为一个简单的入门。
您的 XML 可能类似于以下内容(不过我还没有尝试过):
为了不手动编写每个项目的包位置,Eclipse 和 Ant 之间似乎没有那么好的集成。您可以尝试以下建议:
${basedir}
属性,如 此处-Dworkspace_loc=${workspace_loc}
.project< /code> 来自 Ant 内的文件,使用特定的 XML 解析工具,如 此处
You should be able to add an Ant XML file to your Eclipse project, and fill it with Ant tasks that can run an external program from command line. Probably you should have a separate task item for each device you want to run on, and then a parent task containing all of them.
Then add a single custom builder step to Eclipse project, choosing Ant as builder and pointing to the XML file you added previously (see here)
I'm not a big expert on Ant, but at some point I needed to add a custom task to build a Jar out of my project code from within Eclipse, so that I could run it everytime I needed it (like here). This procedure worked quite well.
The Ant task that should do for you is Exec: http://ant.apache.org/manual/Tasks/exec.html. You might want to have a look at http://ant.apache.org/manual/using.html for a simple starter.
Your XML could be something like the following (I haven't tried it though):
In order to not manually write the package location for each project, there seems to be not such a great integration between Eclipse and Ant. You might try the following suggestions:
${basedir}
property as in here-Dworkspace_loc=${workspace_loc}
.project
file from within Ant, using a specific XML parsing facility as in here这是我的解决方案,可以使用两个快捷键 STRG+S 和 STRG+ALT+F10 在多个设备上轻松构建、安装和启动 Android 应用程序;)
1 。构建 APK
在 Eclipse 中构建 Android 的正常行为是不会创建 APK。但在首选项中可以选择禁用该行为。
=>取消选择该选项后,更改代码后只需按 Strg+S 即可创建 APK 文件。
2.安装和启动
要为多个设备安装并自动启动应用程序,我认为最简单的方法是使用命令行和 Windows 批处理脚本:
在我的例子中,我有三个设备。为了更快地访问一台设备,我使用了以下代码而不是上面代码中的循环。首先,我在最快的设备上安装并启动应用程序,然后在第二台设备上安装并启动应用程序,依此类推。我确信有更好的方法来代替使用 tail、head 和 xargs,但我对批处理文件了解不多,但它只是运行。 ;)
获得 Windows 批处理脚本后,创建该文件的快捷方式。右键单击快捷方式文件并选择属性。您可以在其中指定全局快捷键,例如 STRG+ALT+F10。
在Eclipse中更改一些代码后,您只需按STRG+S,然后按STRG+ALT+F10,应用程序将最终在所有设备上启动。是的! :)
Here is my solution to easily build, install and launch an Android application on multiple devices with exactly two shortcuts STRG+S and STRG+ALT+F10 ;)
1. Build APK
The normal behavior of an Android Build in Eclipse is, that the APK will not be created. But in the preferences is the option to disabled that behavior.
=> After deselecting that option, only a Strg+S is needed to create the APK file after a change in the code.
2. Install and Launch
To install and automatically launch the app for multiple devices, the easiest way is to use the command line and a Windows Batch script in my opinion:
In my case I have three devices. For faster access to one device, I used the following code instead of the loop in upper code. First, I install and launch the app on the fastest device and after that on the second and so on. I am sure there are better ways instead of using tail, head and xargs, but I don't know that much about Batch files, but it just runs. ;)
After having the Windows Batch script, create a shortcut of that file. Right click the shortcut file and select properties. There you can specify a global shortcut key for example STRG+ALT+F10.
After changing some code in Eclipse, you only have to press STRG+S and then STRG+ALT+F10 and the app will be finally launched on all devices. Yeah! :)