Android App development Efficient toolset 1---ant build a simple Android project

Source: Internet
Author: User

In Java compilation Those things mentioned the use of ant to compile the Java project, today extended to use it to build Android projects, in fact, the truth is the same, the change is only the form of use. The benefit of the ant build compared to the IDE is that when multiple sub-projects use a custom jar package, Ant can do a better job of automating the build, and one command will take care of compiling the entire project without manually exporting the jar package and dropping it into the specified directory. This is what efficient building tools are advertised for.

First of all, the installation of Ant under Linux (that article is too simple to write, in fact, it is very simple, do not look at the Mannul in the complexity of writing).

The simplest way to install 1.ant is to install it directly with the Linux system command:
Ubuntu:
sudo apt-get install ant
Fedora:
sudo yum install ant
The disadvantage is that the version on the software server is too old. I am in Fedora 14 (the system version is old enough) the installation version is 1.7.1, and the latest version is 1.9.4, so it is recommended to download the latest version of the installation directly from the official website. If you want to see the source code to choose Source Edition, and I chose Binary Edition, like a free installation version of the software, the steps are as follows:
1) Download. Zip or other format to install the package, unzip to the path you want to place:
[email protected] ant]$ CP ~/downloads/apache-ant-1.9.4-bin.zip. [Email protected] ant]$ unzip apache-ant-1.9.4-bin.zip [[email protected] ant]$ CD Apache-ant-1.9.4[[email protected] AP ache-ant-1.9.4]$ lsbin  fetch.xml   INSTALL  lib      manual  readmeetc  get-m2.xml  KEYS     LICENSE  NOTICE  whatsnew

2) Set Environment variables add the following in. BASHRC:

ant_home=/home/linc/dev/ant/apache-ant-1.9.4 Export java_home=/usr/java/jdk1.6.0_25-Export PATH=${PATH }:${ant_home}/bin
In order for the changes to take effect immediately, execute the source ~/.BASHRC
3) Check that Ant is successfully executed, such as printing the following information, stating that Ant is working.
[Email protected] apache-ant-1.9.4]$ AntBuildfile:build.xml does not exist! Build failed

2.build.xmlant's compilation is based on the Build.xml profile, and the Android SDK has provided us with a template, see <sdk>/tools/ant/build.xml
, what's even more wonderful is that we can use Android tools to generate Build.xml.
Android tool is <sdk>/tools under the tool, from the name can be seen that its ability is very strong. This tool will be a separate opportunity to say, first to briefly explain how it helped create the Build.xml file, we first look at the help:
[[email  protected] ballgame]$ android-h Update Project usage:android [Global Options] Update project [Action O  Ptions] Global options:-H--help:help on a specific command.     -V--verbose:verbose mode, shows errors, warnings and all messages.  --clear-cache:clear the SDK Manager repository manifest cache.                         -S--silent:silent mode, shows errors only. Action "Update Project": Updates an Android project (must already has an androidmanifest.xml). Options:-L--library:directory of an Android library to add, relative to this project ' s director Y.-P--path:the project ' s directory.  [Required]-n--name:project name.  -T--target:target ID to set for the project. -S--subprojects:also updates any projects in sub-folders, such as test projects. 

Except for the parameter-p path is required, other parameters can be taken without. However, the proposed name-n is added, otherwise it is named by the activity name. -T can not be modified, the target ID of the project is actually the version of the Android API, we can view the project's Project.Properties, as a benchmark, as follows:

[Email protected] ballgame]$ tail project.properties ... # project target.target=android-4

Enter the original project ballgame directory and enter the following command:
[[email protected] ballgame]$ Android Update Project  -P. Updated LOCAL.PROPERTIESNO project name specified, using Activity name ' mainactivity '. If you wish to change it, edit the first line of build.xml.Added file./build.xmladded file./proguard-project.txt

You can also specify a more complete parameter:

[[email protected] ballgame]$ Android Update Project  -P.-N ballgame-t android-4updated project.propertiesupdated Lo cal.propertiesupdated file./build.xmlupdated file./proguard-project.txt
At this point, build.xml in the case we did not move a shot.

3. Compile and execute Ant Debug, a debug apk is compiled.


This article takes an example of one of the simplest Android projects to describe the installation and use of Ant. The next article is about the ant build of complex projects.

Android App development Efficient toolset 1---ant build a simple Android project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.