Ant: Create and compile an android Project

Source: Internet
Author: User

Before reading this article, we assume that you have met the following conditions, otherwise reading this article will not help you much.


<1> jdk1.6 is successfully installed in Ubuntu and environment variables are configured.


<2> the ant environment is successfully downloaded and configured in Ubuntu.


<3> In ubuntu, the android-SDK is successfully installed, and the tools and platform-tools environment variables are configured.


Let's get started with ant's Android development journey! /Home/mark/Android/android-sdk-linux_x86 is the path to android_sdk installation.

1. Android commands


Open the terminal and enter the command

android -h

You can list the help and usage of this command. The following command is the focus of this article.

create project: Creates a new Android projectupdate project: Updates an Android project (must already have an AndroidManifest.xml)

Next, let's take a look at the parameters and usage of these two commands. Open the terminal and enter the command

android -h create project

You can see that the output help information is:

Usage:  android [global options] create project [action options]Global options:  -v --verbose  Verbose mode: errors, warnings and informational messages are printed.  -h --help     Help on a specific command.  -s --silent   Silent mode: only errors are printed out.Action "create project":  Creates a new Android project.Options:  -n --name     Project name  -t --target   Target ID of the new project [required]  -p --path     The new project's directory [required]  -k --package  Android package name for the application [required]  -a --activity Name of the default Activity that is created [required]

Similarly, you can look at the usage of another command.

Usage:  android [global options] update project [action options]Global options:  -v --verbose  Verbose mode: errors, warnings and informational messages are printed.  -h --help     Help on a specific command.  -s --silent   Silent mode: only errors are printed out.Action "update project":  Updates an Android project (must already have an AndroidManifest.xml).Options:  -p --path        The project's directory [required]  -l --library     Directory of an Android library to add, relative to this project's directory  -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.

2. Create a project


In the/home/mark path, create an android project. The details are as follows:
Project name: testantandroidactivity
Name: testactivity
Package name: Mark. zhangandroid version: 4, that is, android1.5
In the terminal, you only need:

android create project -k mark.zhang -n TestAntAndroid -a TestActivity -t 4 -p /home/mark/TestAntAndroid

OK. The testantandroid project directory will be created under/home/mark/. Its structure is as follows, which is the same as creating a project using Eclipse/ADT.
Modify the Res/layout/Main. xml file

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><TextView      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="this is my ant compile android app"    android:textSize="20sp"    android:textColor="#aa000a"    /></LinearLayout>

Tip: Run androidlist target to view the installed SDK version.

3. compile the project


You only need two simple commands!

cd /home/mark/TestAntAndroid/ant debug

Go to the/home/mark/testantandroid/bin directory and you can see the AK file:
4. Install APK
Install the above APK file to the simulator to verify whether it is feasible.

cd /home/mark/TestAntAndroid/binadb install TestAntAndroid-debug.apk

5. update existing projects


If the android project already exists, you can update the project (modify the version of the platform) to automatically modify ant configuration files such as build. xml.

android update project -n TestAntAndroid -t 11 -p /home/mark/TestAntAndroid/

Note:-T 11 indicates that Android-11 is used.Of course, you can use another version to update the project. However, if you do not use a later Android version to update a project, an error is reported.

Console display information:

Updated default.propertiesUpdated local.propertiesFile build.xml is too old and needs to be updated.Updated file /home/mark/TestAntAndroid/build.xmlUpdated file /home/mark/TestAntAndroid/proguard.cfg

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.