Table of Contents
Android build system with ant
Adding build.xml to an existing project
Change to project directory and call:
android update project --path . Updated local.properties
Clean and build project to check that's it works.
ant ant clean ant debug ant installd
Creating a new project with build.xml
android create project --name YourProjectName --path $(pwd)/YourProject --target android-19 --package com.company.testproject --activity MainActivity
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.
Customizing the build
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"/>.