Using ANT to build android applications.


To build android application using ANT you can either learn how to create build.xml file and how to configure ANT to work with Android SDK, or you can rely on android tools.

Its better to start your project keeping ANT into consideration. You can use android tool to create project which also creates ant build.xml file which takes care of our almost all regular needs.

Its a very simple 3 step process.

First step: Find all the targets installed on your machine.

anshu@Anshu-Notebook:~$ ~/android-sdk-linux_x86/tools/android list targets
Available Android targets:
id: 1 or "android-3"
Name: Android 1.5
Type: Platform
API level: 3
Revision: 4
Skins: HVGA (default), QVGA-L, HVGA-L, HVGA-P, QVGA-P
id: 2 or "Google Inc.:Google APIs:3"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 3
Description: Android + Google APIs
Based on Android 1.5 (API level 3)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P
id: 3 or "android-4"
Name: Android 1.6
Type: Platform
API level: 4
Revision: 3
Skins: WVGA854, HVGA, QVGA, WVGA800 (default)
id: 4 or "Google Inc.:Google APIs:4"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 1.6 (API level 4)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WVGA854, HVGA, WVGA800 (default), QVGA
id: 5 or "android-7"
Name: Android 2.1-update1
Type: Platform
API level: 7
Revision: 2
Skins: WVGA854, HVGA, WQVGA400, QVGA, WVGA800 (default), WQVGA432
id: 6 or "Google Inc.:Google APIs:7"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 1
Description: Android + Google APIs
Based on Android 2.1-update1 (API level 7)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, WVGA800 (default), QVGA
id: 7 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 2
Skins: WVGA854, HVGA, WQVGA400, QVGA, WVGA800 (default), WQVGA432
id: 8 or "Google Inc.:Google APIs:8"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.2 (API level 8)
Libraries:
* com.google.android.maps (maps.jar)
API for Google Maps
Skins: WQVGA400, WVGA854, HVGA, WQVGA432, WVGA800 (default), QVGA
id: 9 or "Samsung Electronics Co., Ltd.:GALAXY Tab Addon:8"
Name: GALAXY Tab Addon
Type: Add-On
Vendor: Samsung Electronics Co., Ltd.
Revision: 1
Based on Android 2.2 (API level 8)
Skins: WQVGA400, WVGA854, GALAXY Tab (default), HVGA, WQVGA432, WVGA800, QVGA
id: 10 or "android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 1
Skins: WVGA854, HVGA, WQVGA400, QVGA, WVGA800 (default), WQVGA432
id: 11 or "android-11"
Name: Android 3.0
Type: Platform
API level: 11
Revision: 1
Skins: WXGA (default)

Second step: Create android project

anshu@Anshu-Notebook:~$ ~/android-sdk-linux_x86/tools/android create project --target 7 --name SampleAntProject --path ~/android_workspace/SampleAntProject --activity SampleActivity --package com.techjini.sample.ui
Created project directory: /home/anshu/android_workspace/SampleAntProject
Created directory /home/anshu/android_workspace/SampleAntProject/src/com/techjini/sample/ui
Added file /home/anshu/android_workspace/SampleAntProject/src/com/techjini/sample/ui/SampleActivity.java
Created directory /home/anshu/android_workspace/SampleAntProject/res
Created directory /home/anshu/android_workspace/SampleAntProject/bin
Created directory /home/anshu/android_workspace/SampleAntProject/libs
Created directory /home/anshu/android_workspace/SampleAntProject/res/values
Added file /home/anshu/android_workspace/SampleAntProject/res/values/strings.xml
Created directory /home/anshu/android_workspace/SampleAntProject/res/layout
Added file /home/anshu/android_workspace/SampleAntProject/res/layout/main.xml
Created directory /home/anshu/android_workspace/SampleAntProject/res/drawable-hdpi
Created directory /home/anshu/android_workspace/SampleAntProject/res/drawable-mdpi
Created directory /home/anshu/android_workspace/SampleAntProject/res/drawable-ldpi
Added file /home/anshu/android_workspace/SampleAntProject/AndroidManifest.xml
Added file /home/anshu/android_workspace/SampleAntProject/build.xml
Added file /home/anshu/android_workspace/SampleAntProject/proguard.cfg

Third Step: You are ready to start using ANT

anshu@Anshu-Notebook:~$ cd android_workspace/SampleAntProject/
anshu@Anshu-Notebook:~/android_workspace/SampleAntProject$ ant clean
Buildfile: /home/anshu/android_workspace/SampleAntProject/build.xml
[setup] Android SDK Tools Revision 10
[setup] Project Target: Android 2.2
[setup] API level: 8
[setup]
[setup] ------------------
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup]
[setup] ------------------
[setup]
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
[setup]
[setup] Importing rules file: tools/ant/main_rules.xml

clean:
[delete] Deleting directory /home/anshu/android_workspace/SampleAntProject/bin

BUILD SUCCESSFUL
Total time: 1 second
anshu@Anshu-Notebook:~/android_workspace/SampleAntProject$ ant compile
Buildfile: /home/anshu/android_workspace/SampleAntProject/build.xml
[setup] Android SDK Tools Revision 10
[setup] Project Target: Android 2.2
[setup] API level: 8
[setup]
[setup] ------------------
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup]
[setup] ------------------
[setup]
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
[setup]
[setup] Importing rules file: tools/ant/main_rules.xml

-pre-build:

-dirs:
[echo] Creating output directories if needed...
[mkdir] Created dir: /home/anshu/android_workspace/SampleAntProject/bin
[mkdir] Created dir: /home/anshu/android_workspace/SampleAntProject/gen
[mkdir] Created dir: /home/anshu/android_workspace/SampleAntProject/bin/classes

-aidl:
[echo] Compiling aidl files into Java classes...

-renderscript:
[echo] Compiling RenderScript files into Java classes and RenderScript bytecode...

-resource-src:
[echo] Generating R.java / Manifest.java from the resources...

-pre-compile:

compile:
[javac] /home/anshu/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to /home/anshu/android_workspace/SampleAntProject/bin/classes

BUILD SUCCESSFUL
Total time: 2 seconds
anshu@Anshu-Notebook:~/android_workspace/SampleAntProject$

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s