首先让我们看看android命令的详细参数及用法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
root@ithouge-OptiPlex-780:~# android --help
Usage:
android [global options] action [action options]
Global options:
-h --help : Help on a specificcommand.
-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.
Valid
actions
are
composed
of a verb
and an
optional
direct
object:
- sdk : Displays the SDK Manager window.
- avd : Displays the AVD Manager window.
- list : Lists existing targets or virtual devices.
- list avd : Lists existing Android Virtual Devices.
- list target : Lists existing targets.
- list sdk : Lists remote SDK repository.
- 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
AndroidManifest.xml).
- createtest-project : Creates a new Android projectforatestpackage.
- updatetest-project : Updates the Android projectforatestpackage (must
already have an AndroidManifest.xml).
- create lib-project : Creates a new Android library project.
- update lib-project : Updates an Android library project (must already have
an AndroidManifest.xml).
- update adb : Updates adb to support the USB devices declaredinthe
SDK add-ons.
- update sdk : Updates the SDK by suggesting new platforms toinstall
ifavailable.
- create identity : Creates an identityfile.
|
android可执行程序是一个重要的工具:
(1):创建,删除以及查看虚拟设备。
(2):创建,更新Android工程
(3):更新SDK新的平台库,附件组建以及文件。
当然如果你使用的是Eclipse,并且集成了ADT,那么你可以不必直接使用这个执行程序。
//列出所有可用的系统镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
root@ithouge-OptiPlex-780:~# android list targets
Available Android targets:
----------
id: 1 or"android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 3
Skins: WQVGA432, HVGA, WQVGA400, QVGA, WVGA854, WVGA800 (default)
ABIs : armeabi
----------
id: 2 or"Google Inc.:Google APIs:8"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.2 (API level <img src=" http://www.ithouge.com/wp-includes/images/smilies/icon_cool.gif"alt="8)"class="wp-smiley">
Libraries:
* com.google.android.maps (maps.jar)
APIforGoogle Maps
Skins: WVGA854, WQVGA400, HVGA, WQVGA432, WVGA800 (default), QVGA
ABIs : armeabi
----------
id: 3 or"KYOCERA Corporation:DTS Add-On:8"
Name: DTS Add-On
Type: Add-On
Vendor: KYOCERA Corporation
Revision: 1
Description: DTS Add-On
Based on Android 2.2 (API level <img src=" http://www.ithouge.com/wp-includes/images/smilies/icon_cool.gif"alt="8)"class="wp-smiley">
Libraries:
* com.kyocera.dualscreen (dualscreen.jar)
Dual Screen optional platform library
Skins: DTS400 (default), WVGA854, WQVGA400, HVGA, DTS800, WQVGA432, WVGA800, QVGA
ABIs : armeabi
----------
id: 4 or"LGE:Real3D Add-On:8"
Name: Real3D Add-On
Type: Add-On
Vendor: LGE
Revision: 1
Description: Real3D add-on
Based on Android 2.2 (API level <img src=" http://www.ithouge.com/wp-includes/images/smilies/icon_cool.gif"alt="8)"class="wp-smiley">
Libraries:
* com.lge.real3d (real3d.jar)
Real3D library
Skins: WVGA854, WQVGA400, Optimus3D (default), HVGA, WQVGA432, WVGA800, QVGA
ABIs : armeabi
----------
id: 5 or"Samsung Electronics Co., Ltd.:GALAXY Tab Addon:8"
Name: GALAXY Tab Addon
Type: Add-On
Vendor: Samsung Electronics Co., Ltd.
Revision: 1
Based on Android 2.2 (API level <img src=" http://www.ithouge.com/wp-includes/images/smilies/icon_cool.gif"alt="8)"class="wp-smiley">
Skins: WVGA854, WQVGA400, GALAXY Tab (default), HVGA, WQVGA432, WVGA800, QVGA
ABIs : armeabi
----------
id: 6 or"android-9"
Name: Android 2.3.1
Type: Platform
API level: 9
Revision: 2
Skins: WQVGA432, HVGA, WQVGA400, QVGA, WVGA854, WVGA800 (default)
ABIs : armeabi
----------
id: 7 or"Google Inc.:Google APIs:9"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.3.1 (API level 9)
Libraries:
* com.google.android.maps (maps.jar)
APIforGoogle Maps
Skins: WVGA854, WQVGA400, HVGA, WQVGA432, WVGA800 (default), QVGA
ABIs : armeabi
----------
id: 8 or"android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 2
Skins: WQVGA432, HVGA, WQVGA400, QVGA, WVGA854, WVGA800 (default)
ABIs : armeabi
----------
id: 9 or"Google Inc.:Google APIs:10"
Name: Google APIs
Type: Add-On
Vendor: Google Inc.
Revision: 2
Description: Android + Google APIs
Based on Android 2.3.3 (API level 10)
Libraries:
* com.android.future.usb.accessory (usb.jar)
APIforUSB Accessories
* com.google.android.maps (maps.jar)
APIforGoogle Maps
Skins: WVGA854, WQVGA400, HVGA, WQVGA432, WVGA800 (default), QVGA
ABIs : armeabi
|
1:通过命令行管理虚拟设备
以下是创建AVD的一般格式,通过设置参数可以指定avd名称,系统镜像。还可以设置其他的选项,例如:SD卡待大小,模拟器皮肤以及数据存储位置。
1
2
|
android create avd -n -t [-
<option> ] ... </option>
|
参数-n指定模拟器的名称,-t指定系统镜像ID
如果你选择的系统镜像是标准的(不含附件组建),那么android工具会询问你是否要设置自定义的硬件配置。如果需要自定义,则输入相应的值,否则直接按回车键,选择默认。
备注:如果你选择创建的模拟器包含有附加组建,android工具则不会询问设置自定义的硬件参数,它会假定附件已经设置好了特定的参数,所以防止再次重置参数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
root@ithouge-OptiPlex-780:~# android create avd -n platform4.1 -t 20
Auto-selecting single ABI armeabi-v7a
Android 4.1 is a basic Android platform.
Do you wish to create a custom hardware profile [no]yes
Name of the AVD being run:
avd.name []:4.1
Name of the AVD being run:
avd.name []:
Cache partition support: Whether we use a/cachepartition on the device.
disk.cachePartition [yes]:yes
Cache partition: Cache partition to use on the device. Ignoredifdisk.cachePartition is not'yes'.
disk.cachePartition.path []:/tmp/4.1
Cache partition: Cache partition to use on the device. Ignoredifdisk.cachePartition is not'yes'.
disk.cachePartition.path []:
Cache partition size:
disk.cachePartition.size [66MB]:
Initial data partition: If not empty, its content will be copied to the disk.dataPartition.pathfileat boot-time.
disk.dataPartition.initPath []:
Path to data partitionfile: Path to data partitionfile. Cannot be empty. Special value means using a temporaryfile. If disk.dataPartition.initPath is not empty, its content will be copied to the disk.dataPartition.pathfileat boot-time.
disk.dataPartition.path []:
Ideal size of data partition:
disk.dataPartition.size [0]:
Path to the ramdisk image: Path to the ramdisk image.
disk.ramdisk.path []:
Path to snapshot storage: Path to a'snapshot storage'file, where all snapshots are stored.
disk.snapStorage.path []:
Initial system partition image:
disk.systemPartition.initPath []:
Path to runtime system partition image:
disk.systemPartition.path []:
Ideal size of system partition:
disk.systemPartition.size [0]:
Accelerometer: Whether there is an accelerometerinthe device.
hw.accelerometer [yes]:
Audio recording support: Whether the device can record audio
hw.audioInput [yes]:
Audio playback support: Whether the device can play audio
hw.audioOutput [yes]:
Battery support: Whether the device can run on a battery.
hw.battery [yes]:
Configures camera facing back: Must be'emulated'fora fake camera,'webcam'fora web camera, or'none'ifback camera is disabled.
hw.camera.back [emulated]:
Configures camera facing front: Must be'emulated'fora fake camera,'webcam'fora web camera, or'none'iffront camera is disabled.
hw.camera.front [none]:
CPU Architecture: The CPU Architecture to emulator
hw.cpu.arch [arm]:
CPU model: The CPU model (QEMU-specific string)
hw.cpu.model []:
DPad support: Whether the device has DPad keys
hw.dPad [yes]:
GPS support: Whether there is a GPSinthe device.
hw.gps [yes]:
GPU emulation: Enable/Disableemulated OpenGLES GPU
hw.gpu.enabled [no]:
GSM modem support: Whether there is a GSM modeminthe device.
hw.gsmModem [yes]:
Keyboard support: Whether the device has a QWERTY keyboard.
hw.keyboard [no]:
Keyboard charmap name: Name of the system keyboard charmapfile.
hw.keyboard.charmap [qwerty2]:
Keyboard lid support: Whether the QWERTY keyboard can be opened/closed.
hw.keyboard.lid [yes]:
LCD backlight: Enable/DisableLCD backlight simulation,yes-enabled,no-disabled.
hw.lcd.backlight [yes]:
Abstracted LCD density: A value used to roughly describe the density of the LCDscreenforautomatic resource/assetselection.
hw.lcd.density [160]:
LCD color depth: Color bit depth of emulated framebuffer.
hw.lcd.depth [16]:
LCD pixel height:
hw.lcd.height [640]:
LCD pixel width:
hw.lcd.width [320]:
Hardware Back/Homekeys: Whether there are hardware back/homekeys on the device.
hw.mainKeys [yes]:
Deviceramsize: The amount of physical RAM on the device,inmegabytes.
hw.ramSize [0]:
Touchscreentype: Definestypeof thescreen.
hw.screen[touch]:
SD Card support: Whether the device supports insertion/removalof virtual SD Cards.
hw.sdCard [yes]:
SD Card image path:
hw.sdCard.path []:
Magnetic field support: Provides magnetic field senosr values.
hw.sensors.magnetic_field [yes]:
Orientation support: Provides orientation sensor values.
hw.sensors.orientation [yes]:
Proximity support: Whether there is an proximityinthe device.
hw.sensors.proximity [yes]:
Temperature support: Provides temperatore sensor values.
hw.sensors.temperature [yes]:
Track-ball support: Whether there is a trackball on the device.
hw.trackBall [yes]:
kernel boot parameters string.:
kernel.parameters []:
Path to the kernel image: Path to the kernel image.
kernel.path []:
Max VM application heap size: The maximum heap size a Dalvik application might allocate before being killed by the system. Value isinmegabytes.
vm.heapSize [0]:
Created AVD'platform4.1'based on Android 4.1, ARM (armeabi-v7a) processor,
with the following hardware config:
hw.lcd.density=240
disk.cachePartition=yes
vm.heapSize=48
hw.ramSize=512
|
当你创建好一个模拟器之后,android工具会为其在你电脑上创建一个专有的目录,这个目录里面包含有AVD的配置文件,数据镜像,SD卡镜像以及其他和这个虚拟设备有关的文件。这个目录里面并没有包含有系统镜像,但是在AVD配置文件中有系统镜像的路径。
同时android工具会为当前AVD创建一个名为<AVD_name>.ini的文件在.android/avd/ 根目录下。这个文件指明了AVD的目录。
默认情况下,android工具创建AVD目录在~/.android/avd/ (on Linux/Mac), C:\Documents and Settings\<user>\.android\ on Windows XP, and C:\Users\<user>\.android\ on Windows 7 and Vista。如果你想要自定义AVD的存储目录,可以指定参数-p <path>,在创建该AVD的时候。
1
|
android create avd -n my_android1.5 -t 2 -p path/to/my/avd
|
除了上面设置一些AVD基本的参数外,为了测试的需要,建议自定义AVD的分辨率和密度。
在我们测试应用程序的时候,我们应该在不同的AVD或真机上测试,应用不同的屏幕配置(不同屏幕大小与密度的混合)。另外,我们应该设定AVD的物理大小尽可能的接近真机。
1:设定AVD的皮肤
1
|
android create avd -n -t --skin WVGA800
|
选项–skin后面可以是Android事前定义好的皮肤类型,也或则我们可以自定义皮肤,例如:240×432
2:设定AVD的密度
设定这个参数,我们只需在创建AVD的时候,选择自定义AVD参数,在被问及设定屏幕虚拟密度的时候(hw.lcd.density)输入理想中的值,例如:”120″表示低密度的屏幕,”160″表示中等密度的屏幕,”240″表示高密度的屏幕。
//删除AVD
1
2
3
4
5
|
root@ithouge-OptiPlex-780:~# android delete avd -n 4.1GoogleAPIS
Deletingfile/root/.android/avd/4.1GoogleAPIS.ini
Deleting folder/root/.android/avd/4.1GoogleAPIS.avd
AVD'4.1GoogleAPIS'deleted.
|
//更新或移动AVD
1
2
3
4
5
6
|
android move avd -n [-
<option> ] ...
android update avd -n [-</option>
<option> ] ...
</option>
|