Automating Builds on Android – Part 2

      3 Comments on Automating Builds on Android – Part 2

In the previous post, Automating Builds on Android – Part 1, we saw how to setup our projects to automate the build process. In this post, we will automate the process further to make Ant automatically use the passwords for our keystore and alias, label our builds to whatever name we like and put it in a specific location on your system (from where others can access it).

1. To make Ant use the passwords for our keystore automatically, we will create a separate properties file in our project folder where. Let’s name it ““. This file would contain two properties as listed below.

2. We will need to make a small change in our build.xml file to tell Ant to load this property file while building. To do this, we simply add this one line in the build.xml file.

<property file=”” />

If you try to run “ant release” command in your terminal, you will notice that Ant doesn’t ask you to enter your passwords anymore. It has picked up the passwords from your file.

3. Adding a name and a time-stamp to your builds while making a release build needs a little more effort. We will now create another properties file called ““. This file would contain two more properties as listed below.



The file_name_format would be used to name your output builds. Sometimes, you would want to name your builds differently based on whether it is a “daily_build” or “weekly_build” or a “release_build”. Instead of renaming the output file manually, you could just change this property accordingly just before your type in “ant release”, and your builds would automatically be named as you like. The other property, build_location is again a configurable value here, where Ant would put all your builds in the specified location. This could be a shared folder on your system from where anyone else can access it easily.

4. Now comes the lengthy part. To accommodate these changes in our build process, our original build.xml is not enough. We will have to tweak the actual underlying build.xml to make our build process more streamlined. Let’s see how to do it. Pick up the build.xml from the sample project and replace the previous build.xml with this one. It will have a whole lot of Ant scripts. You don’t have to worry about most of it, except for these lines.

    <!– Date/Time format for naming the file–>
        <format property=”time” pattern=”dd_MMM” />
    <property file=”” />
    <property file=”” />
    <property file=”” />

Notice, that, we are using a time-stamp property which we would be using in our build.xml to version our builds based on the specific format. Our builds will be names as “test_build_hello_world_22_SEP.apk”.

The last thing you need to change is this piece of code. You will find it somewhere in the new build.xml.

    <property name=”” value=”${file_name_format}_${time}.apk” />
    <property name=”out.release.file” location=”${build_location}/${}” />

5. Here, you can see that we have changed the property “” to a value that we want the output file to be named as. And also, we changed the “out.release.file” to use our configured directory from the file.

The final step is to run “ant release” for the last time, and you will see your final release build placed at your desired location.

You can find the sample project here.

3 thoughts on “Automating Builds on Android – Part 2

  1. Pingback: Automating Builds on Android – Part 1 | Techdroid

Leave a Reply