1

I'm developing an android subsystem with multiple android applications, using Eclipse. When I make code changes I often need to reinstall the applications by clicking on each of the individual run configurations. This is time consuming. Is there a way of grouping the run configurations to automatically execute them with a single click?

3 Answers 3

1

Turns out its not terribly hard to write a simple command plugin using Eclipse SDK to get and execute a list of launch configurations. I was able to do so starting with the "Hello World" plugin tutorial, which creates a command button on the tool bar, then added dependencies to ResourcesPlugin and DebugPlugin, and the following code to SimplerHandler.java. When the button is clicked this code executes all launch configurations and puts up a little window with info. With a little refinement, the plugin could be made to run a hard-coded set of configurations. I'm guessing its possible to get a handle to the launch favorites and just run those.

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

yea you can write a script in sh in unix or bat in windows but i prefer to write it in plain java using Runtime.exec() you would have to execute something like adb install -r path/bin/file.apk

i use this kind of stuff to automate code generation & android build

3 Comments

Thanks. The problem with this approach is that after a code modification the apk is not rebuilt by Eclipse until after hitting the run configuration. Again, I'd like to make a change in 3-4 projects, then click one button to rebuild the apk and re-install.
Just found an android builder option "skip packaging and dexing until export or launch", which is set by default. That's why my apk wasn't being built even with auto builds turned on. Unfortunately, turning this on slows down auto builds significantly. So I'm still looking for a way of make code changes in several apps, and then generating the apk and installing in one swoop. Will look into ant to see if there's a way to just do the packing and dexing with the auto build classes. Any suggestions welcome.
Okay I wasn't complete. I use this method to rebuild and install apks from source. I have a java program which executes android.bat, ant and adb, the 3 in a row, and automates everything. Of course I spent 2 days writing it and it's not trivial. Maybe an existing tool can do it. Or maybe you have to write it yourself, as I did.
0

monkeyrunner may give you the most platform-independent solution. To install APKs and start Activities you can use something like this:

#! /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)

3 Comments

As with the previous suggestion, this assumes the apk is already built.
If you are using Eclipse and Build Automatically is set your APK is built. Otherwise, you can invoke 'ant' in the script.
No, I tested automatic builds and the apk is not rebuilt on every change to the source code. You need to hit the run config before the apk is built. Running ant is a possibility, but it is considerably slower than rebuilding the apk with Eclipse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.