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
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;
}
Comments
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
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)