Wednesday, February 29, 2012

Android Ant Build - Android Automated Build

I am trying to write very simple tutorial to build Android APK using Ant tool.  To build APK using eclipse is very easy, normally developer use it but in some specially senario you need to build APK using command line. 

Setup Environment 

1. JDK :Install JDK and set JAVA_HOME 
2. Android SDK :Download Android Platforms using Android SDK
3. Ant :Install Ant and set ANT_HOME 
Now, Take your any project developed in eclipse or any other IDE. I am taking project from eclipse.
Step 1 : Copy your project folder from Eclipse Workspace to the Desktop
Step 2 : Create keystore file using keytool command
1keytool -genkey -v -keystore <file name="">.keystore -alias <alias name=""> -keyalg RSA -keysize 2048 -validity 365</alias></file>
Step 3 : Copy keystore file in your project folder
Step 4 : Create "ant.properties" file using any text editor, this file contain information about keystore file. create your keystore file `
1key.store=MyAndroidApp.keystore
2key.alias=MAA
3key.store.password=kpbird
4key.alias.password=kpbird
Step 4 : Create "default.properties" file, If you have created project using eclipse, this file will available, If not create file with following content, change api level as per your project.
01# This file is automatically generated by Android Tools.
02# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
03#
04# This file must *NOT* be checked in Version Control Systems,
05# as it contains information specific to your local configuration.
06 
07 
08# location of the SDK. This is only used by Ant
09# For customization when using a Version Control System, please read the
10# header note.
11sdk.dir=/Users/kpbird/android-sdk-macosx

Step 6 : Create "build.xml" with following content, change project name "MyAndroidProject".
1<project default="help" name="MyAndroidProject">
2    <property file="local.properties">
3    <property file="ant.properties">
4    <loadproperties srcfile="project.properties">
5    <fail message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var" unless="sdk.dir">
6    <import file="${sdk.dir}/tools/ant/build.xml">
7</import></fail></loadproperties></property></property></project>
Step 7 : Now, It's time to start build, open terminal, go to the project folder and execute following command
1ant release
Step 8 : You APK file will be at following path.
1Project Folder -> bin -> MyAndroidProject-release.apk

Summary

Create following files in your Project Folder and execute "ant release" command
  1. keystore
  2. ant.properties
  3. default.properties
  4. local.properties
  5. build.xml
For more information you can refer following link
http://developer.android.com/guide/developing/projects/projects-cmdline.html

1 comment:

  1. Thanks for useful information! also liked this http://www.enterra-inc.com/techzone/using_ant_android_applications_building/

    ReplyDelete