Tuesday, January 1, 2013

Build Android Application Using Ant Script


1.  Jdk 1.6 or later. Set JAVE_HOME to location of the Jdk.
2.  In the Android installation directory there are tools and platform-tools folder. Append the path of these folders to the PATH environment variable.
3.  Download apache-ant from http://ant.apache.org/. I have downloaded apache-ant-1.8.4.zip. 
4.  Extract apache-ant-1.8.4.zip file at any drive at root level.
5.  Add apache-ant/bin to PATH environment variable or at command prompt use the following command:  set PATH=" D:\apache-ant-1.8.4\bin";%PATH%

How to add build.xml file to existing Android project?

It is really simple and easy to add an Ant script file, build.xml, to your existing Android project. Following are the steps:
From command prompt navigate to the root directory of your project.
Enter the following command in order to add the build.xmlto the project.
    >android update project –p <path>
You can see that following files are added to your project:
    -  build.xml
    -  local.properties
    -  proguard-project.txt
Note that the above android command will only work if you have properly set the Android sdk’s tools and platform-tools folder to the PATH environment variable (as mentioned above in Pre-Requisites Step 2).

Build the Android project using Ant Script

This step is really simple, if you have properly set thevvpath of apache-ant/bin folder (as mentioned in Pre-Requisites Step 5).
Enter the following command while you are at the root directory of your Android project:
    -  ant
You will see the detail help of all the ant commands.
    >ant clean command, clean the project
    >ant release command, build the project and creates the unsigned .apk file in the /bin directory of the project.

Please follow my next post Create Signed Build of Android Application using Ant Script if you want to create a signed .apk file of your Android application.


Hi! One question: we can choose de directory when the task puts the apk file?

Using Ant Commands, I think we cannot select a directory. The .apk file is generated in bin folder of the Project. For more detail: http://developer.android.com/tools/building/building-cmdline.html

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More