从Eclipse我怎么能同时执行多个android运行命令?

问题描述:

我正在开发一个使用Eclipse的多个android应用程序的android子系统。当我更改代码时,我经常需要通过单击每个单独的运行配置来重新安装应用程序。这是非常耗时的。有没有办法将运行配置分组以自动执行一次点击?从Eclipse我怎么能同时执行多个android运行命令?

原来它不是太难写使用Eclipse SDK来获取和执行启动配置的列表,一个简单的命令插件。我可以这样做,从“Hello World”plugin tutoria l开始,它在工具栏上创建一个命令按钮,然后将相关性添加到R​​esourcesPlugin和DebugPlugin,并将以下代码添加到SimplerHandler.java。当按钮被点击时,这段代码会执行所有的启动配置,并提供一个带有信息的小窗口。稍微改进一下,插件就可以运行一组硬编码的配置。我猜测它有可能得到启动收藏夹的处理并运行它们。

public Object execute(ExecutionEvent event) throws ExecutionException 
{ 
    StringBuffer sb = new StringBuffer(); 

    // Get root of workspace 
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); 

    // Get projects 
    IProject[] projects = wsRoot.getProjects(); 
    sb.append("projects: " + projects.length); 

    // Get launch manager and launch configurations 
    ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager(); 
    ILaunchConfiguration launchConfigs[] = null; 
    try 
    { 
     launchConfigs = launchMgr.getLaunchConfigurations(); 
    } 
    catch (CoreException e) 
    { 
     e.printStackTrace(); 
    } 
    sb.append(" launch configs:" + launchConfigs.length); 

    for (int i = 0; i < launchConfigs.length; i++) 
    { 
     ILaunchConfiguration config = launchConfigs[i]; 
     String name = config.getName(); 
     sb.append("\nlaunching " + name + "..."); 
     try 
     { 
      config.launch("debug", null, false); 
     } 
     catch (CoreException e) 
     { 
      e.printStackTrace(); 
     } 
    } 

    // Print out the info... 
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); 
    MessageDialog.openInformation(
      window.getShell(), 
      "Ag-eclipse-runner", 
      sb.toString()); 

    return null; 
} 

是啊,你可以写在窗口 在UNIX中的SH脚本或蝙蝠,但我更喜欢使用的Runtime.exec() 把它写在普通的Java,你就必须像adb install -r path/bin/file.apk

我用这个东西执行种类的东西来自动代码生成& android build

+0

谢谢。这种方法的问题在于,在修改代码之后,Eclipse不会重新编译apk直到执行运行配置。再次,我想在3-4个项目中进行更改,然后单击一个按钮重建apk并重新安装。 – 2012-03-31 03:40:09

+0

刚刚发现了一个android builder选项“skip packaging and dexing until export or launch”,这是默认设置。这就是为什么即使打开了自动构建,我的apk也没有被构建的原因。不幸的是,把它打开会显着减慢汽车的构建。所以我仍然在寻找一种在多个应用程序中进行代码更改的方法,然后生成apk并一举安装。将研究蚂蚁,看看是否有办法用自动构建类来做包装和分解。欢迎任何建议。 – 2012-03-31 04:29:29

+0

好吧,我没有完成。我使用这种方法重建并从源代码安装apks。我有一个java程序,它执行android.bat,ant和adb,连续3次,并自动执行一切。当然,我花了2天的时间写下它,这不是微不足道的。也许现有的工具可以做到这一点。或者也许你必须自己写,就像我一样。 – Joel 2012-03-31 15:40:54

monkeyrunner可能会给你最平*立的解决方案。要安装的APK,并开始活动,你可以使用这样的事情:

#! /usr/bin/env monkeyrunner 
# Imports the monkeyrunner modules used by this program 
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice 

# Connects to the current device, returning a MonkeyDevice object 
device = MonkeyRunner.waitForConnection() 

# Installs the Android package. Notice that this method returns a boolean, so you can test 
# to see if the installation worked. 
device.installPackage('myproject/bin/MyApplication.apk') 

# sets a variable with the package's internal name 
package = 'com.example.android.myapplication' 

# sets a variable with the name of an Activity in the package 
activity = 'com.example.android.myapplication.MainActivity' 

# sets the name of the component to start 
runComponent = package + '/' + activity 

# Runs the component 
device.startActivity(component=runComponent) 
+0

与前面的建议一样,这个假设apk已经建好了。 – 2012-03-31 03:42:17

+0

如果您正在使用Eclipse并且设置了自动构建,则您的APK已构建。否则,你可以在脚本中调用'ant'。 – 2012-03-31 03:47:14

+0

不,我测试了自动构建,并且在每次更改源代码时都不重建apk。您需要在apk构建之前点击运行配置。运行蚂蚁是一种可能性,但它比使用Eclipse重建apk要慢很多。 – 2012-03-31 03:54:30