Feb 3, 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
keytool -genkey -v -keystore .keystore -alias  -keyalg RSA -keysize 2048 -validity 365
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 `
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.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
# This file must *NOT* be checked in Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.

Step 6 : Create "build.xml" with following content, change project name "MyAndroidProject".


Step 7 : Now, It's time to start build, open terminal, go to the project folder and execute following command
ant release
Step 8 : You APK file will be at following path.
Project Folder -> bin -> MyAndroidProject-release.apk


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

Use cron job or Hudson for automated build, run "ant release" command from con job or Hudson