Use ant to compile Android Projects

Source: Internet
Author: User
How to compile the android project?

The following is a clear explanation of how to compile the android project in this official document,
I will not talk about too many detailed explanations, rtfm.

What I need to say is that we can allow the IDE to complete compilation for you, or compile the project using the command line method.

What? Command Line? Is it too old?

No! There is always a situation where ide cannot complete compilation. What is the situation?

When your resource files are very large, IDE is on strike. What should I do? Command line to help you.

Previously, we encountered this embarrassing situation in the e-book project melonpan.

Because the program contains a large font, pre-installed books and other resource files (about 100 m +), so when using eclipse for project compilation. Either eclipse will report a memory overflow error, or the crash will be dropped without sound.

So how to compile the project? We thought of the official document about the compilation project.

Thank God there are powerful tools like ant to help us do this.

Ant is a magic horse thing?

First, ant is not an "ant", but an abbreviation of "another neat tool.

It is a tool that automates software compilation, testing, deployment, and other steps. It is mostly used for software development in the Java environment. --- Wikipedia

Official Website: ant Official Website

How to Use ant to compile Android projects?

For the android project, an ant compilation build configuration template has been written in the SDK, which makes it easy to compile the android project using ant.

What should I do?

There are three major steps:

1. Prepare the environment and configure the environment variables.

2. Update the project and automatically generate the ant compilation configuration file

3. compile the project

Prepare the environment and configure Environment Variables

Download the latest ant package from the official website.

Then, add ant's <ant_root> \ apache-ant-x \ bin to the environment variable path (if you want this setting to be effective immediately, you need to log on to the current logout user and then log on again)

In this case, you can enter ant in the command line to test whether the above operations have been completed. If "buildfile: Build. XML does not exist!" is displayed! Build failed "indicates that the above settings have been completed, but the current directory does not have a configuration file for build. xml compilation to guide ant to complete the following operations.

What we need to do below is to use the existing tools to generate the ant compilation configuration file

Update the project to automatically generate ant
Compile the configuration file
android update project -p .
Compile the project

Compile the debug APK:

ant debug

Compile the release APK:

ant release
Tips 

1. Compile the signature APK

Create the ant. properties file under the root path of the project, and configure some necessary parameters for the APK signature in the file. After compilation, the APK is signed!

Ant. properties file template:

key.store=path/to/my.keystorekey.alias=mykeystore

For more tips, refer:

Related Article

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.