Android Application Development efficient tool set 1 --- ant build simple Android project, android1 --- ant

Source: Internet
Author: User

Android Application Development efficient tool set 1 --- ant build simple Android project, android1 --- ant

In java compilation, ant is used to compile Java projects. Today, it is extended to use it to build Android projects. In fact, the principle is the same, and only the form of change is used. Ant builds a jar package that can be used by multiple sub-projects. ant builds a jar package automatically, A command will compile the entire project without manually exporting the jar package and then placing it in the specified directory. This is advertised by efficient building tools.

Let's talk about how to install ant in Linux (the article is too simple, but it is actually very simple, not to mention the complexity of mannul ).

1. The simplest way to install ant is to directly install it using Linux commands:
Ubuntu:
Sudo apt-get install ant
Fedora:
Sudo yum install ant
The disadvantage is that the software server version is too old. I have installed the version 1.7.1 on Fedora 14 (which is old enough) and 1.9.4 on the latest version. Therefore, we recommend that you download the latest version from the official website. If you want to see the Source code, select Source Edition, and I chose Binary Edition, like the installation-free software. The steps are as follows:
1) download. Zip or other installation packages, decompress them to the path you want to place:
[linc@localhost ant]$ cp ~/Downloads/apache-ant-1.9.4-bin.zip .[linc@localhost ant]$ unzip apache-ant-1.9.4-bin.zip [linc@localhost ant]$ cd apache-ant-1.9.4[linc@localhost apache-ant-1.9.4]$ lsbin  fetch.xml   INSTALL  lib      manual  READMEetc  get-m2.xml  KEYS     LICENSE  NOTICE  WHATSNEW

2) set the environment variable to add the following content to. bashrc:

15 export ANT_HOME=/home/linc/dev/ant/apache-ant-1.9.4 16 export JAVA_HOME=/usr/java/jdk1.6.0_25 17 export PATH=${PATH}:${ANT_HOME}/bin
To make the modification take effect immediately, run the following command: source ~ /. Bashrc
3) Check whether ant is successfully executed. For example, if the following information is printed, ant has taken effect.
[linc@localhost apache-ant-1.9.4]$ antBuildfile: build.xml does not exist!Build failed

2. build. xmlant is compiled based on the build. xml configuration file. The Android SDK has provided us with a template. For details, see <sdk>/tools/ant/build. xml.
In addition, we can use the android tool to generate build. xml.
The android tool is a tool under <sdk>/tools. It can be seen from the name that it has strong capabilities. In the future, we will take a separate opportunity to explain how the tool helps create the build. xml file. Let's take a look at the help:
[linc@localhost BallGame]$ android -h update project       Usage:       android [global options] update project [action options]       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 have an AndroidManifest.xml).Options:  -l --library    : Directory of an Android library to add, relative to this                    project's directory.  -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-p path, other parameters are optional. However, we recommend that you add-n. Otherwise, the Activity name is used by default. -T can not be modified. The Target Id of the project is actually the version of the Android API. We can view the project. properties of the project and use this as the benchmark, as shown below:

[linc@localhost BallGame]$ tail project.properties ...# Project target.target=android-4

Go to the BallGame directory of the original project and enter the following command:
[linc@localhost 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 more comprehensive parameters:

[linc@localhost BallGame]$ android update project  -p . -n BallGame -t android-4Updated project.propertiesUpdated local.propertiesUpdated file ./build.xmlUpdated file ./proguard-project.txt
So far, build. xml has been fixed without a single shot.

3. Compile and execute ant debug. A debug apk will be compiled.


This document uses the simplest Android project as an example to describe how to install and use ant. Next, let's talk about ant construction for complex projects.

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.