1

I am using Ant to build my Android project. The Android project is checked into Tortoise SVN. Now when I create a build I want the apk files to ideally get generated into different folders on windows stating the version number of the build. For example on first build (ant release) I would like to have the folder bin/1.0/sample.apk and for the next bin/2.0/sample.apk so I cant maintain different versions.And ideally the version numbers should be version number of the manifest(right?). How can this be done ?

Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103

1 Answers1

14

You can have a custom_rules.xml file in your project that contains the statements for copying your apk to the required folder in a -post-build target. You can use the copy task to take care of it.

To retrieve the version information from the manifest, follow this answer on SO.

A sample of the custom_rules.xml would be:

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
    <xmlproperty file="AndroidManifest.xml" prefix="mymanifest" collapseAttributes="true"/>
    <property name="build.dir" value="bin/${mymanifest.manifest.android:versionName}/" />   
    <target name="-post-build">
        <echo>Version is ${mymanifest.manifest.android:versionName}</echo>
        <copy toDir="${build.dir}" >
            <fileset file="${out.final.file}" />
        </copy>
    </target>
</project>

Note: Currently, the apk is copied to a sub-folder of 'bin' folder. You would have to think of another directory as the 'bin' folder will be deleted on every clean operation.

Community
  • 1
  • 1
Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • Sorry , two days since I ve started using ant - where exactly do I put the custom rules file? And where do I make the entry for it in build.xml. And what exactly do I put in it? – Vrashabh Irde May 10 '12 at 06:58
  • Create the custom_rules.xml in the project root (where you have the build.xml). You do not need to make any changes to the build.xml. However, you can open and try to understand how it works - it is very well documented in line. – Rajesh May 10 '12 at 07:04
  • Thanks! I am gonna try this and get back with either a couple more questions or to mark this answer right :D – Vrashabh Irde May 10 '12 at 07:53
  • Actually i am doing ant release to build and I've included this file. Now no module in the build process knows about this file - so nothing really happens. So where do I put a reference to this file or how do I make sure these rules run? – Vrashabh Irde May 10 '12 at 08:00
  • Please read about [Managing Projects from Command Line](http://developer.android.com/guide/developing/projects/projects-cmdline.html) which will guide you through the process of using ant to build Android projects. The tool also creates a build.xml which you can use without modification along with the above mentioned custom_rules.xml. Please make sure that you read about [Building and Running from the Command Line](http://developer.android.com/guide/developing/building/building-cmdline.html) as well – Rajesh May 10 '12 at 08:05
  • Okay so this creates a file but am new to ant and not clear as to how to take this version name and include it in the filename of the apk build. I read the other answer but it left me more confused. – JPM Oct 10 '12 at 19:58