2012-03-31 77 views

回答

1

原來它不是太難寫使用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; 
} 
0

是啊,你可以寫在窗口 在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

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) 
+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