Tuesday, June 22, 2010

Using Ant to Automate Building Android Applications

The standard way to develop and deploy Android applications is using Eclipse. This is great because it is free, easy to use, and many Java developers already use Eclipse. To deploy your applications using Eclipse, you simply right-click on the on the project, choose to export the application, and follow the prompts

There are a few things we cannot easily do with this system, though. Using the Eclipse GUI does not allow one to easily:
  • Add custom build steps.
  • Use an automated build system.
  • Use build configurations.
  • Build the release project with one command.
Fortunately, the Android SDK comes equipped with support for Ant, which is a common build script system popular among Java developers. It is how you can develop Android applications without using Eclipse, if you so desire. This tutorial will show you how to incorporate an Ant build script into your Android projects (even if you still develop with Eclipse), create your release package ready for Marketplace deployment in one step, create a build configuration using a properties file, and alter your source files based on the configuration.

You can use the Ant build script to solve all of the problems listed above.  This tutorial expects you to already have your Android SDK setup correctly, and to have Ant installed.  It will also help to know a little about Ant if you want to add custom build steps, but you don't really need to know anything to follow the tutorial here.

Although I don't personally use an automated build system for my projects, I do use it to create configuration files and to run custom build scripts. I also believe that it is very important to have a one-step build system, which means that there is only one command to create your final release package (I'll explain why later). You can already run your application in debug mode with Eclipse with one step, but I feel it is important to be able to create the release package in one step as well.

Finally, if this is too much reading for your taste, you can jump straight into the summary for a few simple steps, and download the sample application at the end of the tutorial.

Ant in a nutshell

A build script in Ant is an XML file.  The default filename for a Ant build file is build.xml. Build steps in Ant are called tasks, which are defined by targets in the build file. When you build your Android application with the default build script, you would type ant release at the command line. In this case, Ant looks for the default filename build.xml, and release is the target which it builds. The release target builds the application ready for release (as opposed to for debugging). Another example would be ant clean, which cleans the project binaries.

You can do pretty much anything you can imagine with more custom build scripts, from copying files to making network calls. More detail about how to use Ant is beyond the scope of this tutorial, but I will show you some useful tricks.

One custom script which I enjoy very much uses ProGuard to obfuscate and shrink the code. I see the code size of my applications drop by a whopping 50% using it. It helps for users who may think your application is taking too much space on their device. I'll explain how to do this in a future tutorial.

Adding build.xml to an existing project

If you already have a project that you'd like to add the Ant build script to, then there is an easy command line tool you can use. Open up a command prompt and navigate to the base directory of your project. From there, use the command:
android update project --path .

Here is an example of successful output:
>android update project --path .
Updated local.properties

Added file C:\dev\blog\antbuild\build.xml

If the android command is not found, then you need to update your path to include the Android tools.  On Windows, you can use something like set path=%PATH%;C:\dev\android-sdk-windows\tools (substituting your actual Android installation directory), or even better add it to your path persistently by updating the environment variables through your system properties.

Now you will have a working ant build script in build.xml.  You can test your setup by typing ant at the command prompt, and you should receive something similar to the following boilerplate help:

>ant
Buildfile: C:\dev\blog\antbuild\build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 1.5
    [setup] API level: 3
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
    [setup] Importing rules file: platforms\android-3\ant\ant_rules_r2.xml

help:
     [echo] Android Ant Build. Available targets:
     [echo]    help:      Displays this help.
     [echo]    clean:     Removes output files created by other targets.
     [echo]    compile:   Compiles project's .java files into .class files.
     [echo]    debug:     Builds the application and signs it with a debug key.
     [echo]    release:   Builds the application. The generated apk file must be
     [echo]               signed before it is published.
     [echo]    install:   Installs/reinstalls the debug package onto a running
     [echo]               emulator or device.
     [echo]               If the application was previously installed, the
     [echo]               signatures must match.
     [echo]    uninstall: Uninstalls the application from a running emulator or
     [echo]               device.

BUILD SUCCESSFUL

If the ant command is not found, then you need to update your path. Like above, on Windows use set path=%PATH%;C:\dev\apache-ant-1.8.1\bin (substituting your actual Ant installation directory), or even better update your environment variables.

At this point you should be able to type ant release at the command prompt, which will build the project, placing the unsigned .apk file inside of the bin/ directory.

Note that the output from Ant will show further instructions under -release-nosign: which says to sign the apk manually and to run zipalign.  We'll get to these steps later in the signing section below.

Creating a new project with build.xml

If you've already created your project and followed the above instructions, you can skip this section. If not, you can may either create a new Android project using the regular Eclipse method (via New > Other... > Android Project), and follow the instructions in the above section, or you can use the command line as described here.

android create project --name YourProjectName --path C:\dev\YourProject --target android-3 --package com.company.testproject --activity MainActivity

Here is an example of successful output:

>android create project --name YourTestProject --path c:\temp\TestProject --target android-3 --package com.company.testproject --activity MainActivity

Created project directory: c:\temp\TestProject
Created directory C:\temp\TestProject\src\com\company\testproject
Added file c:\temp\TestProject\src\com\company\testproject\MainActivity.java
Created directory C:\temp\TestProject\res
Created directory C:\temp\TestProject\bin
Created directory C:\temp\TestProject\libs
Created directory C:\temp\TestProject\res\values
Added file c:\temp\TestProject\res\values\strings.xml
Created directory C:\temp\TestProject\res\layout
Added file c:\temp\TestProject\res\layout\main.xml
Added file c:\temp\TestProject\AndroidManifest.xml
Added file c:\temp\TestProject\build.xml

Note: To see the available targets, use android list target and you should see something like:

>android list target
id: 1 or "android-3"
     Name: Android 1.5
     Type: Platform
     API level: 3
     Revision: 4

     Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
In the above case, you can use either 1 or android-3 as the target ID.  In the sample project, I chose android-4, which corresponds to Android 1.6.

Once the project is created, you can test if your project build is setup correctly by typing ant at the command line.  See the above section for further instructions.

Synchronizing with Eclipse

If you open the Ant build script, build.xml, in Eclipse, you will see an error on the second line of the file at this line: <project name="MainActivity" default="help">.  The problem with this line is that it is saying that the default Ant target is "help", but the actual Ant targets used in the build file are imported from another location, which the Eclipse editor does not recognize. The import is done at the line <taskdef name="setup", which imports Ant files from the Android SDK.

Unfortunately, while this error is active in your project, you cannot debug your project from Eclipse, even though the Ant build.xml is not needed. There are two solutions. You can remove default="help" from the file, which will remove the error in Eclipse. If you do this, and type ant at a command prompt without any targets (as opposed to "ant release"), you won't get the default help.  Or, you can copy the imported Ant files directly into your code, which is exactly what you must do if you would like to customize your build. If you follow this tutorial, you won't have to worry about this error. See the Customizing the build section for more information.

Automatically signing your application

Before an application can be delivered to a device, the package must be signed. When debugging using Eclipse, the package is technically signed with a debugging key. (Alternatively, you can build a debug package using ant debug) For actual applications delivered to the Android Marketplace, you need to sign them with a real key. It is useful to put this step into the build process. On top of the ease of automating the process, it allows you to build your application in one step. (One-step builds are a Good IdeaTM)

If you have not already created a key, you can do so automatically using Eclipse (Right click project > Android Tools > Export Signed Application Package...), or follow the instructions here.

Now we must tell the build script about our keystore. Create a file called build.properties in your project's base directory (in the same directory as build.xml and the other properties files), if it does not already exist. Add the following lines:
key.store=keystore
key.alias=www.androidengineer.com

Where keystore is the name of your keystore file and change the value of key.alias to your keystore's alias. Now when you run ant release, you will be prompted for your passwords, and the build will automatically sign and zipalign your package.

Of course, having to enter your password doesn't make for a one-step build process. So you could not use this for an automated build machine, for one thing. It also has the disadvantage of requiring you to type the password, which it will display clearly on the screen, which may be a security issue in some circumstances.  We can put the passwords into build.properties as well, which will solve the issue:
key.store.password=password
key.alias.password=password

Caution: There can be several issues with storing the keystore and passwords. Depending on your organization's security policies, you may not be able to store the passwords in version control, or you may not be able to give out the information to all developers who have access to the source. If you want to check in the keystore and the build.properties file, but not the passwords, you can create a separate properties file which could only be allowed on certain machines but not checked in to version control. For example, you could create a secure.properties file which goes on the build machine, but not checked in to version control so all developers wouldn't have access to it; import the extra properties file by adding <property file="secure.properties" /> to build.xml. Finally, you could always build the APKs unsigned with ant release by not adding any information to the properties files.  The package built using this method will need to be signed and aligned.

Customizing the build

Now that we've got a working Ant build script, we can create a one-step build. But if we want to customize the build further, we'll have to do a few extra steps. You can do anything with your build that you can do with Ant. There are a few things we'll have to do first.

The Ant targets are actually located in the Android SDK.  The targets are what you type after ant on the command line, such as release, clean, etc.  To customize the build further, we need to copy the imported targets into our own build file.

If you look in build.xml, you can see the instructions for how to customize your build steps:

The rules file is imported from
<SDK>/platforms/<target_platform>/templates/android_rules.xml
To customize some build steps for your project:
  - copy the content of the main node <project> from android_rules.xml
  - paste it in this build.xml below the <setup /> task.
  - disable the import by changing the setup task below to <setup import="false" />

Find the android_rules.xml file in your Android SDK. For example, mine is located at C:\dev\android-sdk-windows\platforms\android-4\templates. There, copy almost the entire file, excluding the project node (copy below <project name="MainActivity"> to above </project>), and paste it in your build.xml file. Also, change the line <setup /> to <setup import="false"/>.

Now you can change around the build as you please. Test that the build file is still working properly by running a build.  For an example of what you can do with the custom build script, see the next section.

Using a Java configuration file

This is a great way to use a build property to affect the source code of your Android application. Imagine a configuration class in your project which sets some variables, such as a debugging flag or a URL string. You probably have a different set of these values when developing than when you release your application. For example, you may turn the logging flag off, or change the URL from a debugging server to a production server.

public class Config
{
    
/** Whether or not to include logging statements in the application. */
    
public final static boolean LOGGING = true;
}

It would be nice to have the above LOGGING flag be set from your build. That way, you can be sure that when you create your release package, all of the code you used for debugging won't be included. For example, you may have debugging log statements like this:

if (Config.LOGGING)
{
    
Log.d(TAG"[onCreate] Success");
}

You will probably want to leave these statements on during development, but remove them at release.  In fact, it is good practice to leave logging statements in your source code. It helps with later maintenance when you, and especially others, need to know how your code works. On the other hand, it is bad practice for an application to litter the Android log with your debugging statements. Using these configuration variables allows you to turn the logging on and off, while still leaving the source code intact.

Another great advantage of using this method of logging is that the bytecode contained within the logging statement can be completely removed by a Java bytecode shrinker such as ProGuard, which can be integrated into your build script.  I'll discuss how to do this in a later blog post.

A nice way to set the Config.LOGGING flag is in your build properties.  Add the following to build.properties:
# Turn on or off logging.
config.logging=true

To have this build property be incorporated into our source code, I will use the Ant type filterset with the copy task. What we can do is create a Java template file which has tokens such as @CONFIG.LOGGING@ and copy it to our source directory, replacing the tokens with whatever the build properties values are.  For example, in the sample application I have a file called Config.java in the config/ directory.

public class Config
{
    
/** Whether or not to include logging statements in the application. */
    
public final static boolean LOGGING = @CONFIG.LOGGING@;
}

Please note that this is not a source file, and that config/Config.java is notthe actual file used when compiling the project. The file src/com/yourpackage/Config.java, which is the copied file destination, is what will be used as a source file.

Now I will alter the build file to copy the template file to the source path, but replace @CONFIG.LOGGING with the value of the property config.logging, which is true. I will create an Ant target called config which will copy the above template to the source directory. This will be called before the compile target.

    <!-- Copy Config.java to our source tree, replacing custom tokens with values in build.properties. The configuration depends on "clean" because otherwise the build system will not detect changes in the configuration. -->
<target name="config">

<property name="config-target-path" value="${source.dir}/com/androidengineer/antbuild"/>

<!-- Copy the configuration file, replacing tokens in the file. -->
<copy file="config/Config.java" todir="${config-target-path}"
     overwrite="true" encoding="utf-8">
<filterset>
<filter token="CONFIG.LOGGING" value="${config.logging}"/>
</filterset>
</copy>

<!-- Now set it to read-only, as we don't want people accidentally
    editing the wrong one. NOTE: This step is unnecessary, but I do
    it so the developers remember that this is not the original file. -->
<chmod file="${config-target-path}/Config.java" perm="-w"/>
<attrib file="${config-target-path}/Config.java" readonly="true"/>

</target>

To make this Ant target execute before the compile target, we simply add config to the dependency of compile<target name="compile" depends="config, -resource-src, -aidl". We also make the config target call clean, because otherwise the build system will not detect changes in the configuration, and may not recompile the proper classes.

Note: The above Ant task sets the target file (in your source directory) to read-only.  This is not necessary, but I add it as a precaution to remind me that it is not the original file that I need to edit.  When developing, I will change the configuration sometimes without using the build, and Eclipse will automatically change the file from read-only for me.  I also do not check in the target file into version control; only the original template and build.properties.

Version control

Do not check in the local.properties file which is generated by the Android build tools. This is noted in the file itself; it sets paths based on the local machine. Do check in the default.properties file, which is used by the Android tools, and build.properties, which is the file which you edit to customize your project's build.

I also don't check in the target Config.java in the source directory, nor anything else is configured by the build. I don't want local changes to propagate to other developers, so I only check in the original template file in the config/ directory.

In my projects, when I release a new version of a project I always check in the properties file and tag it in the source repository with a tag name such as "VERSION_2.0". That way we are certain of what properties the application was built with, and we can reproduce the application exactly as it was released, if we later need to.

Summary

1. At the command line run android create project, or android update project in your project base directory if it already exists.
2. (Optional) Add key.store and key.alias to build.properties if you want to include the signing step in your build.
3. (Optional) Add key.store.password and key.alias.password to build.properties if you want to include the keystore passwords, to make the build run without any further input needed.
4. (Optional) If you would like to further customize the build, copy the SDK Ant build code from <SDK>/platforms/<target_platform>/templates/android_rules.xmlto your local build.xml and change <setup /> to <setup import="false"/>.
5. Use ant release to build your project. It will create the package in bin/.

Sample Application

The sample application is a simple Hello World application, but it also includes the custom build script as described in this tutorial.  It also includes the Config.java which is configurable by the build. First, you must run "android update project -p ." from the command line in the project's directory to let the tools set the SDK path in local.properties. Then you can turn on and off logging by changing the value of config.logging in build.properties. Finally, run ant release to build the application, which will create the signed bin/MainActivity-release.apk file ready to be released.

Project source code - antbuild.zip (13.4 Kb)

525 comments:

  1. When I run ant release I get all kinds of errors because it can't find any of the dependencies. Is there an easy way to include the project dependencies or do I have to manually include them by modifying build.xml? (I have dependencies to jar files and other java projects)

    I thought the whole point of using the eclipse project to build is because it knows about dependencies and the full project structure, otherwise I mind as well just manually make javac calls with all the dependencies included.

    ReplyDelete
  2. @Adecus

    If your project builds correctly in Eclipse, and after that you create the build file using the "android update" command but the build file doesn't work, then I suppose the Android tools which create the project do not support automatically adding dependencies to the build file. You probably have to manually update it.

    ReplyDelete
  3. I will try that.

    Also, well written informative post, thank you.

    ReplyDelete
  4. I was having issues referencing a libaray project. I found this info helpful:

    http://www.listware.net/201006/android-developers/56532-android-developers-android-library-broken.html

    ReplyDelete
  5. Thanks a lot for this useful article.

    ReplyDelete
  6. Does anyone know how to use ant to build an app that is link sourced to a library project? Thanks.

    ReplyDelete
  7. Very useful tutorial. Had to properly set the JAVA_HOME (without blanks) and PATH, but once figured out, it worked out well on Win7. Thanks!

    ReplyDelete
  8. Great article and great blog! Thanks for your lessons, I find them really useful.

    ReplyDelete
  9. After letting Eclipse update the add-on, I ended having issues building with ant (despite having no problem right before it). Based on some posts I found (from Google staff), changes that are *not* backward-compatible (thank you!) were introduced in the build process. The solution for my project was not to use android_rules.xml to modify build.xml, but rather ant_rules_r3.xml (under /tools/ant). I could apply the other tasks (e.g. config) and it worked fine.

    ReplyDelete
  10. how do I specify the library .jar files that are located in the project's \lib folder ?

    Is there anything I need to do for the .so files in the project's \libs\armeabi folder ?

    Currently I get a lot of errors like: "package org.anddev.andengine.engine does not exist"

    Eclipse built it fine, but Ant doesn't know about the \lib it seems like.

    ReplyDelete
  11. the solution was to copy the andEngine library JAR's to the \libs folder (I had them in \lib)

    ReplyDelete
  12. Hi Matt,
    excellent article. I have only ever used Eclipse for developing and releasing projects for android, until the use of LVL and Progard became a must have, for security.
    I am using Flurry Analytics in my code, so when I process android update and create a build.xml and local.properties file with required changes, I proceed with ant release. Problem is, I am getting "package com.flurry.android not found" error messages. Can you possibly explain why I might be having this problem and what I may be doing wrong? Should I include the Flurry.jar location in my build or properties files?. Your help would be greatly appreciated.

    ReplyDelete
  13. @Owen

    I can't tell if you're getting those errors at runtime or during the build. In any case, the default folder where additional libraries go is ./libs/. You might want to try copying the library file (which I guess is a .jar file) into that folder. Or you could try changing build properties to change the default library directory, but I'd suggest getting it working by moving the .jar file first.

    ReplyDelete
  14. Hi Matt,

    Sorry, I should have explained the problem was in the build. But.....

    Thanks a million you are a star. Everything worked fine. I also should have noted the post previous to mine (Alex) where he had and resolved the same problem.

    Google needs competent support people like you...Keep up the good work. I think it is appreciated by all.

    ReplyDelete
  15. Hi Matt,

    I am having alot of problems trying to include the Licensing service in my Ant buid.

    I am getting the message:
    "com.android.vending.licensing does not exist."

    "import com.android.vending.licensing.AESObfuscator;"

    default.properties file entry in MyMainProject

    android.library.reference.1=c:\\Users\\LeOwen\\LiveProject\\library
    -----------------------------------
    default.properties file entry in com.android.vending.licensing

    android.library=true

    target=android-8
    --------------------------------

    Altough I have read the google documentation I am still having no luck.

    Can you possibly tell me what other requirements I need to take into consideration for this to work?

    ReplyDelete
  16. @Owen

    Is this a build or a runtime error, "com.android.vending.licensing does not exist."?

    Also, have you tried just copying the appropriate library files into the default libs folder? If you can get that to work, then the problem is how you're configuring the new library folder. If you can't, then it sounds like there may be additional problems that I could help with.

    I use a library in my project at work, and it works fine, at least with the API level 7 and below build setups. But this may be something special with the craziness that the licensing library has to do, and if so, I will look into it further if you give me a little more insight into how you've setup the project. I'll try incorporating the licensing library into the sample project myself. Be sure to tell me everything I need to try to do so, such as where to download it.

    ReplyDelete
  17. Hi Matt,
    I have resolved the problem with the LVL library and Proguard using the ANT build method. because Ofuscating is included, I have decided to put the full description in your Optimizing, Obfuscating and Shrinking Post.

    ReplyDelete
  18. The following process was used to Build, Optimize, Obfuscate and Shrink an android app
    if using windows and eclipse. I Created a separate project from eclipse to avoid corruption that may be caused by typos or incorrect
    project configuration set-up.

    1.
    Create a project root directory and copy the files from eclipse as follows:

    AndroidMainfest.xml
    CLASSPATH file
    PROJECT file
    default.properties
    Add your my.keystore to the root directory

    2.
    Copy the eclipse directories into the project root directory as follows:
    assets
    bin
    gen
    res
    src

    3.
    Create a libs directory and copy any library *.jar files to the directory.
    If you are using flurry, this may be one of them.

    4.
    Create a proguard directory.
    copy the proguard.jar file to the directory.

    create and edit the proguard config.txt file according to documentaion and your project requirements.
    If libs is not included in the proguard process at the bottom of build.xml file, then it should be included
    in the config.txt file as follows:
    -libraryjars path/to/your/libs

    The LVL -keep statement must also be included:
    -keep class com.android.vending.licensing.ILicensingService
    Put config.txt in the proguard directory.

    5.
    locate the market_licensing\libary directory located in your eclipse project and copy to
    your Project path.

    The final Project Path setup should consist of:

    PROJECTROOT
    assets
    bin
    gen
    res
    src
    libs (*.jars)
    library (Android LVL)
    proguard


    6.
    Ensure a path to the android.sdk-windows/tools directory has been set up or cd to the location.
    enter android update project --path C:\path\to\your\project
    A local.properties and build.xml file will be created in the project rood directory.

    7. build.xml
    You may need to edit and tailor the build.xml file for your project requirements. I copied
    the ant_rules_r3.xml file located in android-sdk-windows\tools\ant into the build file, and set
    setup import="false"

    8. build.properties file
    Any configuration changes are placed in this file.
    Include the android LVL library path as follows:
    android.library.reference.1=library

    To automate your signing process, add the keystore and password statements (depending on your site restrictions)

    key.store=your.keystore
    key.alias=youralias
    key.store.password=yourkeystorepassword
    key.alias.password=youraliaspassword


    If the above instructions are followed or the project configuration has been set up according to your
    own requirements, then navigate to your Project root directory and enter.

    ant release

    The build should complete successfully.

    I put most of the above in a batch script to automate the process. You also don't need to create
    a separate project if you feel confident with what is in place from eclipse, but you will have
    to include proguard and libs in your eclips project path and you won't have control of buid.xml or build properties
    for external sources. It is up to you.

    Good luck.

    ReplyDelete
  19. The following process was used to Build, Optimize, Obfuscate and Shrink an android app
    if using windows and eclipse. I Created a separate project from eclipse to avoid corruption that may be caused by typos or incorrect
    project configuration set-up.

    1.
    Create a project root directory and copy the files from eclipse as follows:

    AndroidMainfest.xml
    CLASSPATH file
    PROJECT file
    default.properties
    Add your my.keystore to the root directory

    2.
    Copy the eclipse directories into the project root directory as follows:
    assets
    bin
    gen
    res
    src

    3.
    Create a libs directory and copy any library *.jar files to the directory.
    If you are using flurry, this may be one of them.

    4.
    Create a proguard directory.
    copy the proguard.jar file to the directory.

    create and edit the proguard config.txt file according to documentaion and your project requirements.
    If libs is not included in the proguard process at the bottom of build.xml file, then it should be included
    in the config.txt file as follows:
    -libraryjars path/to/your/libs

    The LVL -keep statement must also be included:
    -keep class com.android.vending.licensing.ILicensingService
    Put config.txt in the proguard directory.

    5.
    locate the market_licensing\libary directory located in your eclipse project and copy to
    your Project path.

    The final Project Path setup should consist of:

    PROJECTROOT
    assets
    bin
    gen
    res
    src
    libs (*.jars)
    library (Android LVL)
    proguard


    6.
    Ensure a path to the android.sdk-windows/tools directory has been set up or cd to the location.
    enter android update project --path C:\path\to\your\project
    A local.properties and build.xml file will be created in the project rood directory.

    7. build.xml
    You may need to edit and tailor the build.xml file for your project requirements. I copied
    the ant_rules_r3.xml file located in android-sdk-windows\tools\ant into the build file, and set
    setup import="false"

    8. build.properties file
    Any configuration changes are placed in this file.
    Include the android LVL library path as follows:
    android.library.reference.1=library

    To automate your signing process, add the keystore and password statements (depending on your site restrictions)

    key.store=your.keystore
    key.alias=youralias
    key.store.password=yourkeystorepassword
    key.alias.password=youraliaspassword


    If the above instructions are followed or the project configuration has been set up according to your
    own requirements, then navigate to your Project root directory and enter.

    ant release

    The build should complete successfully.

    I put most of the above in a batch script to automate the process. You also don't need to create
    a separate project if you feel confident with what is in place from eclipse, but you will have
    to include proguard and libs in your eclips project path and you won't have control of buid.xml or build properties
    for external sources. It is up to you.

    Good luck.

    ReplyDelete
  20. Can you give me an example for ant build.xml with android library project?
    Thanks

    ReplyDelete
  21. A very useful article. Thanks!!!

    ReplyDelete
  22. Very nice and useful post. Thanks

    ReplyDelete
  23. Very useful and informative. Thank you.

    ReplyDelete
  24. Very helpfull! Thanks!

    ReplyDelete
  25. Make sure to use the following rules file instead of the one in the platform\template folder, otherwise you will get build errors like aaptexec doesn't support the "basename" attribute:

    android-sdk\tools\ant\main_rules.xml

    ReplyDelete
  26. The article is well written. However, the following must be kept in mind to avoid the baseline and other errors people have reported. I spent an hour getting this to work and finally discovered the problem as detailed here:

    http://stackoverflow.com/questions/4464461/compile-error-while-trying-to-compile-android-app-with-ant

    ReplyDelete
  27. You made my day.

    Many thanks.

    ReplyDelete
  28. A very useful article. Thanks!

    ReplyDelete
  29. Thanks for the great post.

    Here's a tip for using the android logger when the phone is not connected.

    http://www.softllc.com/archives/125

    ReplyDelete
  30. Awesome! Very informative.

    ReplyDelete
  31. Kudos to u, Excellent stuff !!

    I was able to setup my build system in less than hour.

    Thanks a million ;D

    ReplyDelete
  32. i dont know why, so many people talking about android, and i dont know too, why steve jobs is very angry about this? can you mention to me?

    ReplyDelete
  33. Very helpful for all Android developers

    ReplyDelete
  34. Thanks a lot for your article! http://www.enterra-inc.com/techzone/ hope this coulsd be useful, too.

    ReplyDelete
  35. Thank you for this interesting article. There is one thing I am wondering about: You show how to set the logging flag from the build, but in order to be truly useful, IMHO you would need to have the build set the logging flag dependent on if you build for debug or release, for example by defining the filter with

    What do yo think?

    ReplyDelete
  36. Thanks for doing this article. I'm not sure why I found the official docs so intimidating--this is clear and easy!

    I did find one change in the Android version I'm running.

    Instead of putting the properties in build.properties, they need to be in ant.properties

    (The docs say to do that now, at "Build signed and aligned" on
    http://developer.android.com/guide/developing/building/building-cmdline.html#ReleaseMode )

    Thanks again! This is a great timesaver!!

    ReplyDelete
  37. Thanks for the post, very insightful!

    ReplyDelete
  38. Thanks for this useful post!!

    ReplyDelete
  39. Great tutorial. This was very helpful Thank you for posting it!

    ReplyDelete
  40. That was agreat help for me

    Thanks alot!!

    ReplyDelete
  41. Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
    but i did it, still the error is there, any help?

    ReplyDelete
  42. Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
    but i did it, still the error is there, any help?

    ReplyDelete
  43. Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
    but i did it, still the error is there, any help?

    ReplyDelete
  44. Great info. I am about to modify ant/Eclipse and this helps a lot.

    ReplyDelete
  45. Nice tutorial but an engineer using Windows... really? XD

    ReplyDelete
  46. could u pls elborate the same with the help pf Hudson, that would be more helpful

    ReplyDelete
  47. Hello, I have been trying to execute the sample project given here. But when I build the 'build.xml' file I am getting this error-"taskdef class com.android.ant.SetupTask cannot be found". All the environment variables are set accordingly.I cant figure out the problem.Could you please help me out.

    ReplyDelete
  48. buddy you have to setup this particular environment as path "android-home=[YOUR PATH HERE]"
    until you specify the system doesn't know where the ant setup is, hope this will resolve this issue

    ReplyDelete
  49. also check this link
    http://blog.klacansky.com/matter-code/ant-taskdef-class-com-android-ant-setuptask-cannot-be-found

    ReplyDelete
  50. How do you set the "config.logging" property to be true or false depending on what target you're building? (debug or release)

    ReplyDelete
  51. > How do you set the "config.logging" property to be true or false depending on what target you're building? (debug or release)

    See the sample project - the ant build script does it for you, depending on whether you are running the debug or release build.

    ReplyDelete
  52. This comment has been removed by the author.

    ReplyDelete
  53. Thanks for the article. I still have a question though.
    We have a build machine for automated building/testing and that runs through an ant build script which I have setup to do a variety of things.
    We also have Eclipse setup with C/C++ configurations of debug/release (this is a Java & NDK project), but what I need to do is be able to tie the C/C++ config to the Java side such that I can get the Java and C code on the same page so to speak. Have you done this?
    Regards, Guy

    ReplyDelete
  54. very informative post!!
    can you please provide me the code how i can customize my builds.. I need to have generate 3 builds from single source code...

    if possible please do the needful.
    rvikatiyar@gmail.com

    ReplyDelete
  55. Thanks for this useful post. Anyway, are you also behind the web http://androidjayavelu.blogspot.com.es/ ?

    ReplyDelete
  56. This doesn't work anymore with Revision 22 of the Android SDK. Some jar-files are missing.

    Took me some hours to figure out.

    ReplyDelete
  57. Although this is an old article, it is still excellent. Also it does work for SDK-version 22 after some research.

    As my project used an external library for Google Play Services, I needed to update the library project and create a build xml for that library in the same way as for my own project.

    Secondly the new build.xml refers to a ant.properties file instead of the build.properties file.

    Thanks for sharing. Also thanks to many commentors above who added valueable information as well.

    ReplyDelete
  58. Please remove your black background color it is very difficult to read.

    ReplyDelete
  59. Hi Matt,
    Is there any way to run Ant script to run online to compile my android source files online and generate .apk as well as..

    Thanks.

    ReplyDelete
  60. How to include android play services library in ant command. Plz explain in detail..

    ReplyDelete
  61. My project had a dependent library project, I had to use the following command

    android update project --path . --subprojects --target android-10

    ReplyDelete
  62. Hi Matt,

    This is an incredible article. It's 4 years later and still applicable. Thank you so much for writing it up and sharing. Too bad you aren't writing new articles...that's a loss for the rest of us.

    Cheers!

    ReplyDelete
  63. how to remain package

    ReplyDelete
  64. Hi

    I got that Error: Missing argument for flag -p. in CMD when I typed
    android project update -p

    anybody can help me with that .
    Thanks in advance

    ReplyDelete
  65. Hi,

    First of all nice tutorial, i have a small issue. i can able to take unsigned apk but that apk is not working on device. i got an error like "There was a problem while parsing the package" .

    Thanks,
    Peter

    ReplyDelete
  66. Long path tool is the best solution for your problem. try it and solve your problem

    ReplyDelete
  67. You can also use Long Path Tool to sort out this problem.

    ReplyDelete
  68. nice post.but my problem is if my android project has multiple dependency projects then how we
    generate signed apk file using ant tool....thanks

    ReplyDelete
  69. Good tutorial on use of Ant build script to develop Android Applications in cases where Eclipse is difficult to use.

    mobile app development

    ReplyDelete
  70. Thanks for this info, it's a good tutorial. By the way, are you looking for android developers? Visit MyOptimind

    ReplyDelete
  71. Nice tutorial on use of Ant scripts in Android app development,thanks
    mongodb development company

    ReplyDelete
  72. The Android build is a complex process and use of Ant makes the things simpler.

    mobile apps development company

    ReplyDelete
  73. Good job!! Hope you will share more information regarding Ant Scripts in Android app development. Android app Development company

    ReplyDelete
  74. Thanks for sharing with us this informative and helpful article .

    ReplyDelete
  75. that's look amazing thank you for sharing with us .

    ReplyDelete
  76. Its really a nice share to the people, keep sharing good post.

    ReplyDelete
  77. Its really an awesome post. This blog helps to improve knowledge about various Android applications. Thanks for sharing this.

    ReplyDelete
  78. Good Job. Very informative blog. It's really helpful for Android Application Development company for making new apps.

    ReplyDelete
  79. Thanks for sharing about the topic about the android

    ReplyDelete
  80. I like the way you conduct your posts. Have a nice Thursday!
    fmwhatsapp apk download

    ReplyDelete

  81. I will right away seize your rss as I can not find your e-mail subscription link or e-newsletter service. Do you've any? Kindly let me understand so that I may subscribe. Thanks. hotmail sign in

    ReplyDelete
  82. fmwhatsapp latest apk download for android. FM Whatsapp apk download.

    ReplyDelete
  83. Keep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information. Thanks for your valuable efforts. W3webschool - Kolkata SEO Training
    SEO Training

    ReplyDelete
  84. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge so keep on sharing such kind of an interesting blogs.
    ibm datapower online training

    ReplyDelete
  85. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Best Education Based Study Material Check Now Here!

    ReplyDelete
  86. Great tutorial. This was very helpful Thank you for posting it! I think that I should share this blog with my friends and others.

    ReplyDelete
  87. Thank you for sharing this valuable information!

    ReplyDelete
  88. Very good post.
    All the ways that you suggested for find a new post was very good.
    Keep doing posting and thanks for sharing.11:38 AM 9/10/2018
    mobile repairing course in hyderabad

    ReplyDelete
  89. It has been just unfathomably liberal with you to give straightforwardly what precisely numerous people would've promoted for an eBook to wind up making some money for their end, basically given that you could have attempted it in the occasion you needed.offshore safety course in chennai

    ReplyDelete
  90. It’s always so sweet and also full of a lot of fun for me personally and my office colleagues to search you blog a minimum of thrice in a week to see the new guidance you have got.
    industrial safety course in chennai

    ReplyDelete
  91. Nice article i was really impressed by seeing this article,
    it was very interesting and it is very useful for me.
    I get a lot of great information from this blog. Thank you for your sharing this informative blog..
    laptop chiplevel training in hyderabad

    ReplyDelete
  92. Hey, very nice site. I came across this on Google, and I am stoked that I did. I will definitely be coming back here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment. Thanks for sharing.

    Mobile Application Development

    ReplyDelete

  93. Thanks for your info.its very useful for android app development.

    Android Course in bangalore

    ReplyDelete
  94. This comment has been removed by the author.

    ReplyDelete
  95. great content at your platform keep it up and join our latest active Girls WhatsApp Group Link

    ReplyDelete
  96. Great job and please keep sharing such an amazing article and its really helpful for us thank you.
    Selenium Training in Chennai | SeleniumTraining Institute in Chennai

    ReplyDelete
  97. hey amazing if you are looking for Good Instagram Caption please check out my blog

    ReplyDelete
  98. Thanks for providing a useful article containing valuable information. start learning the best online software courses.

    Workday HCM Online Training

    ReplyDelete
  99. Greetings from Florida! I’m bored at work, so I decided to browse your site on my iPhone during lunch break. the information you provide here and can’t wait to take a look when I get home.
    nebosh course in chennai
    offshore safety course in chennai

    ReplyDelete
  100. This is very great thinks. It was very comprehensive post and powerful concept. Thanks for your sharing with as. Keep it up....
    Software Testing Training in Chennai | Software Testing Training Institute in Chennai

    ReplyDelete
  101. Very informative blog and useful article thank you for sharing with us , keep posting learn more about aws with cloud computing

    AWS Online Training

    AWS Certification

    ReplyDelete
  102. Thanks for sharing such a nice info.I hope you will share more information like this. please keep on sharing!


    IBM WebSphere Interview Questions


    Informatica Interview Questions and Answers


    Informatica MDM Interview Questions and Answers

    ReplyDelete
  103. One of the best content i have found on internet for Data Science training in Chennai .Every point for Data Science training in Chennai is explained in so detail,So its very easy to catch the content for Data Science training in Chennai .keep sharing more contents for Trending Technologies and also updating this content for Data Science and keep helping others.
    Cheers !
    Thanks and regards ,
    DevOps course in Velachery
    DevOps course in chennai
    Best DevOps course in chennai
    Top DevOps institute in chennai

    ReplyDelete
  104. very informative blog and useful article thank you for sharing with us, keep posting learn more
    Tableau Training

    Data Science Certification

    Dot net Course

    Android app development Course

    ReplyDelete
  105. Appericated the efforts you put in the content of Data Science .The Content provided by you for Data Science is up to date and its explained in very detailed for Data Science like even beginers can able to catch.Requesting you to please keep updating the content on regular basis so the peoples who follwing this content for Data Science can easily gets the updated data.
    Thanks and regards,
    Data Science training in Chennai
    Data Science course in chennai with placement
    Data Science certification in chennai
    Data Science course in Omr

    ReplyDelete
  106. Thanks for the article - Using Ant to Automate Building Android Applications, I have bookmarked it.

    ReplyDelete
  107. Nice article it contains a lot of useful information so thanks for sharing this valuable post.

    ReplyDelete
  108. .Thanks for taking the time to discuss that,
    I feel strongly about this and so really like getting to know more on this kind of field.
    Do you mind updating your blog post with additional insight?
    It should be really useful for all of us.
    Digital marketing service in sehore
    website designer in sehore

    ReplyDelete
  109. Gun Shot Strike Mod Apk is a new action capturing game. Is a globe loaded with dealing with as well as glory? Every element of the video game will make you really feel shocked. Now that you are an expert battle task force shooter, your goal is to damage all opponents. Hold your weapon and locate the terrorists around you through the radar.

    They do not know your presence, yet when you start Gun Shot Strike Mod Apk the adversary will find your presence, so be extremely careful. Attention to the enemy’s strike, to shield their very own safety. mission accomplished. Depending on the degree of Gun Shot Strike Mod Apk Unlimited Money and AI, you will encounter a number of obstacles. The world’s best multiplayer Basketball Stars Mod Apk No Root facilitate on reduced, from the makers of different raving accomplishment online redirections excitements! Sniper Killer Shooter Mod Apk is the really amazing game with the high graphics and setting with this you can play the game easily and without any hesitation so this game includes many features and the moded version has also

    Now you have a new mission! A terrorist team has occupied the S city, pirating innocent guests as hostages. As an excellent mercenary and also your goal is to eliminate all the terrorists and rescue the hostages. Here you require a cool head abnormality evaluation and quickly, aggressive, precise shooting methods, permit your head to cool down, to enjoy this tough video game now!

    ReplyDelete
  110. Thanks for sharing excellent information.If you Are looking Best smart autocad classes in india,
    provide best service for us.
    autocad in bhopal
    3ds max classes in bhopal
    CPCT Coaching in Bhopal
    java coaching in bhopal
    Autocad classes in bhopal
    Catia coaching in bhopal

    ReplyDelete
  111. This is a nice and informative post thanks for the information!
    Saludpulso.com

    ReplyDelete
  112. This comment has been removed by the author.

    ReplyDelete
  113. Appericated the efforts you put in the content of Artificial intelligence.The Content provided by you for Artificial intelligence is up to date and its explained in very detailed for Artificial intelligence like even beginers can able to catch.Requesting you to please keep updating the content on regular basis so the peoples who follwing this content for Artificial intelligencecan easily gets the updated data.
    Thanks and regards,
    Artificial intelligence training in chennai.
    Artificial intelligence course in chennai with placement.
    Artificial intelligence certification in Chennai.
    Artificial intelligence course in OMR.
    Top Artificial intelligence institute in Chennai.
    Best Artificial intelligence in Chennai.

    ReplyDelete
  114. This is really a big and great source of information. We can all contribute and benefit from reading as well as gaining knowledge from this content just amazing experience Thanks for sharing such a nice information.

    DedicatedHosting4u.com

    ReplyDelete
  115. Very interesting blog Awesome post. your article is really informative and helpful for me and other bloggers too

    Workday Online Training

    ReplyDelete
  116. thanks for information about automatice application

    ReplyDelete
  117. This comment has been removed by the author.

    ReplyDelete
  118. Awesome post. The information you shared was awesome. keep sharing this type of blogs. Stair lifts | Home elevators

    ReplyDelete
  119. Thank you for such a sweet tutorial - all this time later, I've found it and love the end result. I appreciate the time you spent sharing your skills.
    How to Use a Dremel to Cut Glass?
    How to Use a Dremel Tool?
    How to Carve Wood with a Dremel Tool?

    ReplyDelete

  120. Such a wonderful blog on Python .Your blog having almost full information about
    Python .Your content covered full topics of Python ,that it cover from basic to higher level content of
    Python .Requesting you to please keep updating the data about Python in upcoming time if there is some addition.
    Thanks and Regards,
    Python tution in Chennai .
    Python workshop in chennai.
    Python training with certification in Chennai.

    ReplyDelete
  121. Thank you for providing the valuable information ...

    If you want to connect with AI (Artificial Intelligence) World

    as like Python , RPA (Robotic Process Automation)Tools and Data -Science related more information then meet on EmergenTeck Training Institute .

    Thank you.!

    ReplyDelete
  122. It is very nice article on that topic. I was looking for something like which is interesting and knowledgeable. Do you know that Agrawal Construction Company has the most amazing townships, especially Best flats In Bhopal, with the name Sagar Green Hills. It is located in the lap of nature.

    ReplyDelete
  123. Great post. Thanks for sharing a clear step by step process on getting in the nice.
    thank you.
    servicenow service mapping training

    ReplyDelete
  124. Thanks for the information
    For Blockchain training in bangalore,visit:
    Blockchain training in bangalore

    ReplyDelete
  125. Great article ...Thanks for your great information, the contents are quiet interesting. I will be waiting for your next post.
    GCP Training
    Google Cloud Platform Training
    GCP Online Training
    Google Cloud Platform Training In Hyderabad

    ReplyDelete
  126. Magnificent article!!! the blog which you have shared is informative...Thanks for sharing with us...
    salesforce Training in Bangalore
    uipath Training in Bangalore
    blueprism Training in Bangalore

    ReplyDelete