在Eclipse中,如何同时执行多个android运行命令?
我正在使用Eclipse开发一个包含多个android应用程序的android子系统。当我修改代码时,我通常需要通过单击每个单独的运行配置来重新安装应用程序。这很费时。是否有一种方法可以对运行配置进行分组,以便通过单击自动执行它们?是的,您可以在unix中用sh或windows中用bat编写脚本 但我更喜欢使用Runtime.exec()用普通java编写 您必须执行类似于在Eclipse中,如何同时执行多个android运行命令?,android,eclipse,Android,Eclipse,我正在使用Eclipse开发一个包含多个android应用程序的android子系统。当我修改代码时,我通常需要通过单击每个单独的运行配置来重新安装应用程序。这很费时。是否有一种方法可以对运行配置进行分组,以便通过单击自动执行它们?是的,您可以在unix中用sh或windows中用bat编写脚本 但我更喜欢使用Runtime.exec()用普通java编写 您必须执行类似于adb install-r path/bin/file.apk的操作 我用这种东西来自动生成代码&安卓构建是的,你可以在un
adb install-r path/bin/file.apk的操作
我用这种东西来自动生成代码&安卓构建是的,你可以在unix中用sh编写脚本,也可以在windows中用bat编写脚本
但我更喜欢使用Runtime.exec()用普通java编写
您必须执行类似于adb install-r path/bin/file.apk的操作
我使用这种东西来自动生成代码&android build可能会为您提供最独立于平台的解决方案。要安装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)
可以为您提供最独立于平台的解决方案。要安装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)
事实证明,使用EclipseSDK编写一个简单的命令插件来获取并执行一系列启动配置并不十分困难。我可以从“Hello World”l开始,它在工具栏上创建一个命令按钮,然后向ResourcesPlugin和DebugPlugin添加依赖项,并向SimpleHandler.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;
}
public Object execute(ExecutionEvent事件)抛出ExecutionException
{
StringBuffer sb=新的StringBuffer();
//获取工作区的根目录
IWorkspaceRoot wsRoot=ResourcesPlugin.getWorkspace().getRoot();
//获取项目
IProject[]projects=wsRoot.getProjects();
sb.追加(“项目:+项目长度”);
//获取启动管理器和启动配置
ILaunchManager launchMgr=DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration launchConfigs[]=null;
尝试
{
launchConfigs=launchMgr.getLaunchConfigurations();
}
捕获(COREE)
{
e、 printStackTrace();
}
sb.append(“启动配置:+launchConfigs.length”);
对于(int i=0;i
事实证明,使用EclipseSDK编写一个简单的命令插件来获取并执行启动配置列表并不十分困难。我可以从“Hello World”l开始,它在工具栏上创建一个命令按钮,然后向ResourcesPlugin和DebugPlugin添加依赖项,并向SimpleHandler.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;
}
public Object execute(ExecutionEvent事件)抛出ExecutionException
{
StringBuffer sb=新的StringBuffer();
//获取工作区的根目录
IWorkspaceRoot wsRoot=ResourcesPlugin.getWorkspace().getRoot();
//获取项目
IProject[]projects=wsRoot.getProjects();
sb.追加(“项目:+项目长度”);
//获取启动管理器和启动配置
ILaunchManager launchMgr=DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration launchConfigs[]=null;
尝试
{
launchConfigs=launchMgr.getLaunchConfigurations();
}
捕获(COREE)
{
e、 printStackTrace();
}
sb.append(“启动配置:+launchConfigs.length”);
对于(int i=0;i
谢谢。这种方法的问题是,在修改代码之后,Eclipse在点击运行配置之后才重新构建apk。同样,我想在3-4个项目中进行更改,然后单击一个按钮重建apk并重新安装。刚刚发现一个android builder选项“在导出或启动之前跳过打包和索引”,这是默认设置的。这就是为什么我的apk即使在自动构建打开的情况下也没有被构建。不幸的是,启用此选项会显著降低自动构建的速度。因此,我仍然在寻找一种方法,在几个应用程序中进行代码更改,然后生成apk并一次性安装。将查看ant,看看是否有一种方法可以对自动构建类进行打包和索引