Android|Android SDK中的必会工具-android

前面的内容请参见Android应用自动化测试-提纲。 本篇我们介绍在Android SDK中另一个重要的命令,Android命令。android命令主要是操作sdk相关的一些指令
android sdk/avd Android sdk命令用于打开sdk manager的窗口界面
【Android|Android SDK中的必会工具-android】android update sdk命令用于更新当前的sdk
android avd用于打开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]

    推荐阅读