命令行工具
Eclipse是一个非常好用的IDE工具,事实上创建,编译,运行一个Android应用程序并不需要可视化的IDE,Android命令行提供了这一部分功能,包括在Windows和Linux下的,就象编译JAVA,然后IDE背后所执行的正是这些命令行的操作。
用Windows命令行创建一个Shell Activity
在SDK的目录下的Tools下,一个名为ActivityCreator.bat的文件,但是在SDK1.5版以后这个文件已经没有了,取而代之的是Android.bat,除了ActivityCreator的功能,还承担了创建AVD的功能。用记事本打开这个文件粗略的看一下,Android.bat用来创建应用程序开发的环境。
通过Android -h查看命令行的帮助,如下:
C:/Users/conan>android -h
Usage:
android [global options] action [action options]
Global options:
-v --verbose Verbose mode: errors, warnings and informational messages are pr
inted.
-h --help Help on a specific command.
-s --silent Silent mode: only errors are printed out.
Valid actions are composed of a verb and an optional direct object:
- list : Lists existing targets or virtual devices.
- list avd : Lists existing Android Virtual Devices.
- list target : Lists existing targets.
- create avd : Creates a new Android Virtual Device.
- move avd : Moves or renames an Android Virtual Device.
- delete avd : Deletes an Android Virtual Device.
- update avd : Updates an Android Virtual Device to match the folders
of a new SDK.
- create project : Creates a new Android project.
- update project : Updates an Android project (must already have an Androi
dManifest.xml).
- create test-project : Creates a new Android project for a test package.
- update test-project : Updates the Android project for a test package (must al
ready have an AndroidManifest.xml).
- create lib-project : Creates a new Android library project.
- update lib-project : Updates an Android library project (must already have a
n AndroidManifest.xml).
- update adb : Updates adb to support the USB devices declared in the
SDK add-ons.
- update sdk : Updates the SDK by suggesting new platforms to install
if available.
C:/Users/conan>android list target
Available Android targets:
id: 1 or "android-7"
Name: Android 2.1-update1
Type: Platform
API level: 7
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
id: 2 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
id: 3 or "android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 1
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
id: 4 or "android-11"
Name: Android 3.0
Type: Platform
API level: 11
Revision: 1
Skins: WXGA (default)
C:/Users/conan>android create project --name CreateTest --target 2 --path c:/Tes
t --package com.dd --activity ActivityM
Created project directory: c:/Test
Created directory C:/Test/src/com/dd
Added file c:/Test/src/com/dd/ActivityM.java
Created directory C:/Test/res
Created directory C:/Test/bin
Created directory C:/Test/libs
Created directory C:/Test/res/values
Added file c:/Test/res/values/strings.xml
Created directory C:/Test/res/layout
Added file c:/Test/res/layout/main.xml
Created directory C:/Test/res/drawable-hdpi
Created directory C:/Test/res/drawable-mdpi
Created directory C:/Test/res/drawable-ldpi
Added file c:/Test/AndroidManifest.xml
Added file c:/Test/build.xml
Added file c:/Test/proguard.cfg
C:/Users/conan>
创建一个Android项目的命令是android create project,这个命令有5个参数,与Eclipse中设置是一致的,需要注意的是--target这个参数,需要通过Android list target查看相应的Target的ID,本例中,使用Android2.2,id为2。
通过上面的命令可以生成下面的工程目录结构,
与使用IDE生成有一些轻微的差别,手动生成多了一个Build.xml文件,这个文件包含了一些指令阐明了如何将.java文件生成功能性的Android项目。
接下来使用Ant编译程序!