从Eclipse中如何同时执行多个android运行命令?

时间:2012-03-31 00:18:47

标签: android eclipse

我正在使用Eclipse开发一个带有多个Android应用程序的android子系统。当我进行代码更改时,我经常需要通过单击每个单独的运行配置来重新安装应用程序。这很费时间。有没有办法将运行配置分组,只需单击即可自动执行它们?

3 个答案:

答案 0 :(得分:1)

使用Eclipse SDK编写一个简单的命令插件来获取和执行启动配置列表并不是非常困难。我能够从“Hello World”plugin tutoria l开始,它在工具栏上创建一个命令按钮,然后将依赖项添加到ResourcesPlugin和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;
}

答案 1 :(得分:0)

是的,你可以在unix中使用sh或在windows中使用bat来编写脚本 但我更喜欢使用Runtime.exec()在普通的java中编写它 你必须执行adb install -r path/bin/file.apk

之类的东西

我使用这种东西来自动化代码生成和android build

答案 2 :(得分:0)

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)