前面的內容請參見Android應用自動化測試-提綱。 本篇我們介紹在Android SDK中另一個重要的命令,Android命令。android命令主要是操作sdk相關的一些指令
android sdk/avd
<b>Android sdk</b>命令用于打開sdk manager的窗口界面
<b>android update sdk</b>命令用于更新當前的sdk
<b>android avd</b>用于打開avd manager的窗口界面
android list
這個命令可以用來列出當前設備上android主要組件的信息. 如果只需要看到基本信息,可以加上-c參數
android list devices
這里不是像adb devices那樣列出當前連接的設備,而是列出當前設備上可用的模擬設備鏡像類型,如:
> android list devices -c
tv_1080p
tv_720p
wear_round
wear_round_chin_320_290
wear_square
Galaxy Nexus
Nexus 10
Nexus 4
Nexus 5
Nexus 6
Nexus 7 2013
Nexus 7
Nexus 9
Nexus One
Nexus S
2.7in QVGA
2.7in QVGA slider
3.2in HVGA slider (ADP1)
3.2in QVGA (ADP2)
3.3in WQVGA
3.4in WQVGA
3.7 FWVGA slider
3.7in WVGA (Nexus One)
4in WVGA (Nexus S)
4.65in 720p (Galaxy Nexus)
4.7in WXGA
5.1in WVGA
5.4in FWVGA
7in WSVGA (Tablet)
10.1in WXGA (Tablet)
android list target
這個命令用于列出當前設備上的android sdk API版本
>android list target
Available Android targets:
----------
id: 1 or "android-10"
Name: Android 2.3.3
Type: Platform
API level: 10
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
Tag/ABIs : default/armeabi, default/x86
----------
id: 2 or "android-17"
Name: Android 4.2.2
Type: Platform
API level: 17
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : default/x86
----------
id: 3 or "android-23"
Name: Android 6.0
Type: Platform
API level: 23
Revision: 3
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : default/x86_64
----------
id: 4 or "android-24"
Name: Android 7.0
Type: Platform
API level: 24
Revision: 2
Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in
Tag/ABIs : default/arm64-v8a, default/x86_64
需要注意這個target ID,在我們后面自動化測試時,指定對應的android api版本時需要經常用到
android list avd
這個命令用于列出當前已經創建的android模擬器
android list sdk
這個命令用于列出目前sdk的可用包清單
AVD相關
通過android命令,可以在命令行中實現虛機的創建、銷毀等操作。這對于我們自動化時動態管理模擬器是非常有用的
android create avd
Options:
-t --target : Target ID of the new AVD. [required]
-a --snapshot: Place a snapshots file in the AVD, to enable persistence.
-c --sdcard : Path to a shared SD card image, or size of a new sdcard for
the new AVD.
-p --path : Directory where the new AVD will be created.
-b --abi : The ABI to use for the AVD. The default is to auto-select the
ABI if the platform has only one ABI for its system images.
-d --device : The optional device definition to use. Can be a device index
or id.
-n --name : Name of the new AVD. [required]
-s --skin : Skin for the new AVD.
-g --tag : The sys-img tag to use for the AVD. The default is to
auto-select if the platform has only one tag for its system
images.
-f --force : Forces creation (overwrites an existing AVD)
如:
>android create avd -t 1 -n avd233 -b x86
Android 2.3.3 is a basic Android platform.
Do you wish to create a custom hardware profile [no]
Created AVD 'avd233' based on Android 2.3.3, Intel Atom (x86) processor,
with the following hardware config:
hw.lcd.density=240
hw.ramSize=256
vm.heapSize=24
project相關
android命令的另一個重要功能是可以通過命令行直接創建android應用項目以及測試項目
android create project
Options:
-n --name : Project name.
-a --activity : Name of the default Activity that is created.
[required]
-k --package : Android package name for the application. [required]
-v --gradle-version: Gradle Android plugin version.
-t --target : Target ID of the new project. [required]
-g --gradle : Use gradle template.
-p --path : The new project's directory. [required]
android create test-project
Options:
-m --main : Path to directory of the app under test, relative to the test
project directory. [required]
-p --path : The new project's directory. [required]
-n --name : Project name.
android create uitest-project
Options:
-n --name : Project name.
-p --path : The new project's directory. [required]
-t --target : Target ID of the new project. [required]