Export multiple apk for different market using ant

2019-07-25 09:05发布

问题:

My Android app is targeted to 20+ market, each with several different properties in the Manifest.xml.
To release 20+ apk one after another is really time-consuming, and I tried to use the windows batch file to do the release job in a single click.
For now, I use the solution provided by the tutorial here to change the field in the Manifest.xml, but I don't know ant well, so I use a very hack method to do the job in batch file like below:

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
....

Is there some elegant way to accomplish this? like just editing targets in build.xml to do it in ant, etc.

回答1:

First off, why are you always starting a new cmd process? If you just called Ant 20x+ times in your build script it would start building the next build right after the current one would be finished.

Secondly I would advise you to have 20x+ different AndroidManifest.xml files (have a prefix or suffix for each file, so that none of them are named exactly "AndroidManifest.xml") and then you just rename them to AndroidManifest.xml before each build. You can do that with the custom_rules.xml Ant build file (put it next to your build.xml) like this:

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

Here I assumed you renamed your manifests as AndroidManifest.xml.xxxxx. Note also the "-pre-build" target which is invoked before the actual build of the apk starts.

Then just add other "config-" targets and set it's values to whatever you renamed your AndroidManifest.xml(s) to. Then write your build script with 20x+ lines of Ant with "ant config-xxxxx release" where xxxxx is the appropriate config of your build.



回答2:

My final solution:
Define task:

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

Then include ant-contrib*.jar as the answer here so that I can use loop in ant. Then define a new task below

<target name="deploy" >

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

Use “ant deploy” to do the task.
market_channels should be defined in ant.property as follow:

market_channels=google-play,other,...


标签: android ant cmd