Android CLI 专家
本技能提供使用 android CLI 工具的说明。该工具包含各种命令,用于创建项目、运行应用程序、与设备交互以及管理 CLI 环境。
安装
如果 android 工具未在路径中,请安装它。运行以下命令进行安装:
Linux: curl -fsSL https://dl.google.com/android/cli/latest/linux_x86_64/install.sh | bash
Mac Arm: curl -fsSL https://dl.google.com/android/cli/latest/darwin_arm64/install.sh | bash
Mac Intel: curl -fsSL https://dl.google.com/android/cli/latest/darwin_x86_64/install.sh | bash
Windows: curl -fsSL https://dl.google.com/android/cli/latest/windows_x86_64/install.cmd -o "%TEMP%\i.cmd" && "%TEMP%\i.cmd"
SDK 管理
要管理 Android SDK 和工具的安装,请使用 sdk 命令。例如:
android sdk install <package>[@<version>]...:安装特定包。可以指定多个包,用空格分隔。<version>默认为最新版本。例如:android sdk install platforms/android-30@2 platforms/android-34android sdk update [<pkg-name>]:将特定包或所有包更新到最新版本。android sdk remove <pkg-name>:从本地 SDK 中移除一个包。android sdk list --all:列出已安装和可用的 SDK 包。
项目创建
使用 create 命令从模板创建项目。
例如:android create empty-activity --name="My App" --output=./my-app
与 Android 设备交互
使用 android layout 命令以 JSON 格式检查 Android 应用程序的 UI 布局。
使用 android screen 命令直观检查 UI 并获取可视区域的边界坐标。
重要: 在使用 android layout 或 android screen 之前,您必须阅读此参考:interact.md
参考文件 interact.md 包含正确与 Android 设备交互的说明。请严格遵循其说明进行操作。
运行旅程测试
旅程测试涉及设备交互;请使用 android layout 和 android screen 命令来评估旅程。
此处也适用设备交互的说明。
重要: 在评估旅程之前,您必须阅读此参考:journeys.md 参考文件 journeys.md 包含正确评估 Android 旅程的说明。请严格遵循其说明进行操作。
文档搜索
docs 命令在 Android 知识库中搜索权威、高质量的 Android 开发者文档。
通过提供几个关键词,该工具将返回包含如何使用 Android API 或库的示例或指南的高质量文章。
使用此工具获取有关如何完成 Android 特定任务或了解 Android API、界面、库或设备的更多信息。
始终使用此工具获取有关 Android 概念的最新信息。典型用例包括:
- 寻找 API 的迁移指南。
- 寻找 API 的示例。
- 寻找有关 Android API 的最新信息。
- 寻找 Android 概念的最佳实践。
运行 APK
使用 run 命令运行 Android 应用程序。
管理模拟器
使用 android emulator 命令管理 Android 虚拟设备 (AVD)。
捕获截图
使用 android screen 命令捕获已连接 Android 设备当前屏幕的图像并输出到文件。
管理技能
使用 android skills 命令管理 Android 的代理技能。
更新 CLI
使用 android update 命令更新 Android CLI。
android help 输出
Usage: android [-Vhv] [--sdk=PARAM] [COMMAND] -h, --help Show the help message for this command --sdk=PARAM Path to the Android SDK -v, --verbose Enable verbose output for troubleshooting -V, --version Print version information and exit Commands: completion Installs shell autocomplete configuration for the Android CLI in the current user profile create Create a new Android project from available templates. Allows specifying project name, output directory, minSdk, and dry-run execution describe Analyzes an Android project to generate descriptive metadata. This command identifies and outputs the paths to JSON files that detail the project's structure, including build targets and their corresponding output artifact locations (e.g., APKs). This information enables other tools and commands to locate build artifacts efficiently docs Android documentation commands for searching and fetching developer documentation from the official knowledge base emulator Manage Android Virtual Devices (AVDs). Includes commands to start, stop, list, and view details about emulators help Shows the help of all commands info Print environment information including SDK location, connected devices, and configuration variables. Use specific fields to narrow the output init Initializes the environment for the Android CLI. Sets up required configurations, directories, and default skills install Install an Android Application (one or more APKs) to a connected device or emulator without activating any components using incremental optimizations for faster deployment than adb layout Returns the layout tree of an application run Build, deploy, and launch an Android application on a connected device or emulator screen Commands to view the device sdk Manage the Android SDK installation. Includes commands to install, update, remove, and list available and installed SDK packages skills Manage Android CLI skills. Includes commands to install, remove, list, and search for skills by keyword studio Android Studio commands update Update the Android CLI to the latest version
completion Usage: android completion [-h] [] Installs shell autocomplete configuration for the Android CLI in the current user profile
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
Positional Parameters:
<shell> If provided, print the given shell completion without
installing. Supported: bash, zsh
create Usage: android create [-h] [--application-id=PARAM] [--list] [--min-sdk=PARAM] [--name=PARAM] [--namespace=PARAM] [--output=PARAM] [] Create a new Android project from available templates. Allows specifying project name, output directory, minSdk, and dry-run execution
Options:
--application-id=PARAM The application ID for the application
(e.g. 'com.example.myapp')
-h, --help Show the help message for this command
--list List all available templates
--min-sdk=PARAM The 'minSdk' supported by the
application (default is defined in the
template)
--name=PARAM The name of the application (e.g. 'My
Application')
--namespace=PARAM The namespace for resources and package
name for Kotlin source files
-o, --output=PARAM The destination project directory path
(default is '.')
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for
troubleshooting
-V, --version Print version information and exit
Positional Parameters:
<template-name> The template name
describe Usage: android describe [-h] [--project_dir=PARAM] Analyzes an Android project to generate descriptive metadata. This command identifies and outputs the paths to JSON files that detail the project's structure, including build targets and their corresponding output artifact locations (e.g., APKs). This information enables other tools and commands to locate build artifacts efficiently
Options:
-h, --help Show the help message for this command
--project_dir=PARAM The project directory to describe
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
docs Usage: android docs [-h] [COMMAND] Android documentation commands for searching and fetching developer documentation from the official knowledge base
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
Commands:
fetch Fetch an Android documentation article from a URL (kb://...)
search Search Android documentation. Enclose keywords in quotes
emulator Usage: android emulator [-h] [COMMAND] Manage Android Virtual Devices (AVDs). Includes commands to start, stop, list, and view details about emulators
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
Commands:
create Creates a virtual device
list Lists available virtual devices
remove Delete a virtual device
start Launches the specified virtual device. This command will
return when the emulator is fully started and ready to use
stop Stops the specified virtual device
help Usage: android help [-h] [COMMAND] Shows the help of all commands
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
Positional Parameters:
COMMAND The command to show help for
info Usage: android info [-h] [] Print environment information including SDK location, connected devices, and configuration variables. Use specific fields to narrow the output
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
Positional Parameters:
<field> The specific field to print the value of. If omitted print
all
init Usage: android init [-h] Initializes the environment for the Android CLI. Sets up required configurations, directories, and default skills
Options:
-h, --help Show the help message for this command
android options:
--sdk=PARAM Path to the Android SDK
-v, --verbose Enable verbose output for troubleshooting
-V, --version Print version information and exit
install Usage: android install [-h] [--apks=PARAM] [--device=PARAM] [--install-options=PARAM] [--use-delta-install] Install an Android Application (one or more APKs) to a connected device or emulator without activating any components using incremental optimizations for faster deployment than adb
Options:
--apks=PARAM The paths to the APKs, comma separated
--device=PARAM The device serial number
-h, --help Show the help message for this command
--install-options=PARAM Additional options/flags to pass to
package manager install (e.g. -g,-d)
--use-delta-install Use fast delta install (speeds up
incremental updates by transferring
only modified code and resources;
default: true)
android options:
--sdk=PARAM Path to the Android SDK
-v, --ve