2012-07-30 73 views
1

我的Android應用程序面向20多個市場,每個市場都有Manifest.xml中的幾個不同屬性。
要一個接一個地釋放20+個apk文件是非常耗時的,我嘗試使用windows批處理文件來單擊執行釋放工作。
現在,我使用教程here提供的解決方案來更改Manifest.xml中的字段,但我不知道螞蟻好了,所以我使用非常黑客的方法來完成批處理文件中的作業如下:使用螞蟻爲不同市場導出多個apk

start cmd.exe /c "ant config-google-play release_mine" 
REM the line below is for waiting for the former task to finish 
ping 1.1.1.1 -n 1 -w 90000 > nul 
start cmd.exe /c "ant config-eoemarket release_mine" 
ping 1.1.1.1 -n 1 -w 90000 > nul 
.... 

有沒有一些優雅的方式來實現這一目標?就像在build.xml中編輯目標,在ant中執行它等一樣。

回答

0

我的最終解決方案:
定義任務:

<target name="modify_manifest"> 
     <property 
      name="version.market" 
      value="${channel}"/> 
     <property 
      name="out.final.file" 
      location="${out.absolute.dir}/${ant.project.name}_${channel}_${project.version.name}.apk"/> 

     <antcalltarget="release"/> 
    </target> 

然後包括螞蟻的contrib的* .jar這裏的answer,這樣我可以在螞蟻使用循環。然後在下面定義一個新任務

<target name="deploy" > 

    <foreach 
     delimiter="," 
     list="${market_channels}" 
     param="channel" 
     target="modify_manifest" > 
    </foreach> 
</target> 

使用「ant deploy」執行任務。
market_channels應該在ant.property中定義如下:

market_channels=google-play,other,... 
0

首先,你爲什麼總是開始一個新的cmd進程?如果您在構建腳本中只調用了Ant 20x +次,那麼將在當前構建完成後立即開始構建下一個構建。其次我建議你有20x +不同的AndroidManifest.xml文件(每個文件都有一個前綴或後綴,這樣它們都不會被完全命名爲「AndroidManifest.xml」),然後你只需將它們重命名爲AndroidManifest。每個構建之前的xml。你可以做到這一點與custom_rules.xml Ant構建文件(把它旁邊的build.xml文件)是這樣的:

<project name="custom_rules"> 
    <target name="config-google-play"> 
    <property name="version" value="google_play" /> 
    </target> 

    <target name="-pre-build"> 
    <copy tofile="${basedir}/AndroidManifest.xml" overwrite="true"> 
     <fileset file="${basedir}/AndroidManifest.xml.${version}" /> 
    </copy> 
    </target> 
</project> 

這裏我以爲你改名的表現爲AndroidManifest.xml.xxxxx。還要注意在APK的實際構建開始之前調用的「-pre-build」目標。

然後,只需添加其他「config-」目標並將其值設置爲您將AndroidManifest.xml重命名爲的任何值。然後用「ant config-xxxxx release」用20x + Ant行編寫構建腳本,其中xxxxx是構建的適當配置。