Android efficient application Development Toolset 1---Ant to build a simple Android project

Source: Internet
Author: User

In Java compiling those things by referring to Ant compiling the Java project, now expands to use it to build Android, in fact, the truth is connected. Change is only the form of use. Ant build is better than the IDE's advantage when multiple sub-projects use their own custom jar packages, Ant is able to complete its own proactive build. A command will take care of compiling the entire project without manually exporting the jar package and then placing it in the specified folder.

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 easy, do not look at the Mannul of the complex).

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 number on the software server is too old. I am in Fedora 14 (this system version number is old enough) the installation version number is 1.7.1, and the latest version number is 1.9.4, so it is recommended to download the latest version number installation directly from the official website. Suppose you want to look at the source code and choose Edition. And I chose binary Edition. Like a free-to-install version of the software, the process is as follows:
1) Download. Zip or other format installation 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) environment variable settings include the following in. BASHRC For example:

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. Run the source ~/.BASHRC
3) Check that ant is running successfully, 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
, it is even more wonderful that we can use Android tools to generate Build.xml.
The Android tool is a tool under <sdk>/tools. The ability to see it from the name is very strong. This tool will be a separate opportunity to say, first to introduce how it helps to create build.xml files, 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. 

In addition to the parameter-p path is required, other parameters can be taken without.

But the proposed name-N to be added. Otherwise, the activity name will be named by default. -T can not be changed, the target ID of the project is actually refers to the Android API version number, we can view the project Project.Properties, as a benchmark. For example, the following:

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

Go to the original Project Ballgame folder. Enter commands such as the following:
[[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 number of parameters:

[[email protected] ballgame]$ Android Update Project  -P.-N ballgame-t android-4updated project.propertiesupdated Lo cal.propertiesupdated file./build.xmlupdated file./proguard-project.txt
So far. Build.xml the case when we didn't move a shot.

3. Compile and run Ant Debug. A debug apk is compiled.


This article takes one of the simplest Android projects as an example of state ant installation and use.

Next talk about the complex project Ant built.

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Android efficient application Development Toolset 1---Ant to 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.