Back to top

vogella training Training Books

Building Android Application with Apache Ant - Tutorial

Lars Vogel

Version 0.2

28.02.2012

Revision History
Revision 0.1 24.08.2011 Lars
Vogel
Created
Revision 0.2 28.02.2012 Lars
Vogel
bugfixes and enhancements

Android Application with Apache Ant

This article describes how create Android Applications with the command line tool and how to build it via Apache Ant.


Table of Contents

1. Building Android Applications
1.1. Android SDK and ADT
1.2. Maintain PATH
2. Apache Ant
3. Prerequisites
3.1. Android
3.2. Apache Ant
3.3. JDK
4. Example: Building Android Applications with Ant
5. Start
6. Thank you
7. Questions and Discussion
8. Links and Literature
8.1. Source Code
8.2. Android Resources
8.3. vogella Resources

1. Building Android Applications

1.1. Android SDK and ADT

The Android SDK provides tooling for the command line to create and build Android projects.

The Android Development Tools offer tools for Eclipse to create and build Android applications. In Eclipse you can manually export Android applications via the Eclipse wizard.

To build and deploy Android application the Android SDK provide tools based on Apache Ant. Tooling for building Android Application with Maven are also available.

1.2. Maintain PATH

Building Android outside Eclipse involves using the command line or shell. You should be familiar with using a shell in case you want to be able to perform this tutorial.

Make sure that the tools and platform-tools folder of the Android SDK installation directory are part of your PATH environment variable.

2. Apache Ant

The Eclipse project generation wizard does not create the required Apache Ant build.xml file. You can generated it on the command line.

android update project -p . 

Now you can build your project via Apache Ant.

// Clean the project
ant clean

// Build a debug version
ant debug

// Builds the debug version
// and installs it
ant debug install 

If you want to release your application you can create the ant.properties file in your project directory. In this file you point to your signing key and the alias for it.

key.store=path/to/my.keystore
key.alias=mykeystore 

You can now create a release build.

// Build release 
ant release 

3. Prerequisites

3.1. Android

The following assumes that you are familiar with Android development. Please see Android Development Tutorial for an introduction.

3.2. Apache Ant

This tutorial only covers the Android specific settings of Apache Ant. Please see the Apache Ant Tutorial for an introduction into Apache Ant.

3.3. JDK

Build Android applications with Apache Ant requires that the Java Development Kit (JDK) is installed and not only the Java Runtime Environment. Make sure that javac is in the current classpath.

4. Example: Building Android Applications with Ant

Create a new Android project called "de.vogella.android.build.firstant" with the Eclipse Android project wizard. The created project does not include the Apache Ant "build.xml" file.

Switch to the command line and into the directory which contains you new Android project. Type the following to create your build.xml file.

android update project -p . 

Now you can build and deploy your project via Apache Ant.

// Clean the project
ant clean

// Build a debug version
ant debug

// Builds the debug version
// and installs it
ant debug install 

5. Start

You can also start your application via the command line. For this you use adb shell to send an intent to your Activity.

adb shell am start -a android.intent.action.MAIN 
  -n de.vogella.android.build.firstant/.MainActivity 

6. Thank you

Please help me to support this article:

Flattr this

7. Questions and Discussion

Before posting questions, please see the vogella FAQ. If you have questions or find an error in this article please use the www.vogella.com Google Group. I have created a short list how to create good questions which might also help you.

8. Links and Literature

8.1. Source Code

Source Code of Examples

8.3. vogella Resources

vogella Training Android and Eclipse Training from the vogella team

Android Tutorial Introduction to Android Programming

GWT Tutorial Program in Java and compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test your application

Git Tutorial Put everything you have under distributed version control system