用途
本技能是 Google 官方 android CLI 面向 Kotlin Multiplatform(KMP)项目的集成说明层。它不复制 CLI 自身的命令参考——命令语法应始终查阅官方 android-cli 技能(github.com/android/skills/tree/main/devtools/android-cli),后者由 Google LLC 维护,是 create、describe、emulator、run、sdk、docs、screen、layout、studio、skills、info、init、update 等全部子命令的权威来源。本技能只回答一个额外问题:这些命令如何作用于 KMP 项目的多模块结构。
适用前提:项目由 kotlin-multiplatform-feature-scaffold 生成(或任何带 Android target 模块的 Gradle 项目),且本机已安装 android CLI。
主要能力
- 解释 android describe --project_dir=<KMP 根目录> 可在多模块 Gradle 构建中遍历并报告各 target 的构建/输出路径,包括嵌套在图中的 Android target,用于获取 APK 路径,避免手工猜测 androidApp/build/outputs/apk/debug/... 这类可能随 AGP 版本变化的路径。
- 说明 android run --apks=<describe 给出的路径> 可一步完成部署与启动,替代 ./gradlew installDebug && adb shell am start -n ... 的两步操作。
- 指出 android create 面向全新的、仅 Android 的项目模板(如 empty-activity),不理解六层 :model/:api/:domain/:data/:presenter/:ui 模块图,因此不应在已搭建的 KMP 项目上使用;添加 Android target 应使用 kotlin-multiplatform-feature-scaffold。
- 说明 emulator 与 sdk 管理(android emulator create/start/stop、android sdk install)与项目形态无关,按上游技能文档使用即可。
- 对 android studio * 系列 IDE 集成子命令,要求先执行 android studio check;在无头代理会话或 CI 中若无符合条件的 Studio,应回退到 kotlin-multiplatform-roborazzi 的 runComposeUiTest/截图测试,并用 grep/读源码代替 find-declaration/find-usages。
- 提供将稳定命令接入 CI 的思路,例如在 GitHub Actions 中安装 CLI、执行 describe、创建并启动模拟器、安装 SDK、运行 connectedDebugAndroidTest;并明确不应在 CI 中加入依赖运行中 Android Studio 的 android studio * 步骤。
使用方式
安装(官方 CLI): Linux:curl -fsSL https://dl.google.com/android/cli/latest/linux_x86_64/install.sh | bash macOS Apple Silicon:curl -fsSL https://dl.google.com/android/cli/latest/darwin_arm64/install.sh | bash macOS 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" 验证:android info;更新:android update
建议先安装官方技能本身: android skills find android-cli android skills add android-cli
回答顺序约定:先确认是否已安装 android(android info)与官方 android-cli 技能(android skills find android-cli);再判断问题是否 KMP 特有(模块布局、多模块图中的 APK 路径),是则依据本技能,否则转上游命令参考;若任务需要 android studio *,先以 android studio check 把关并说明回退方案;CI 接入仅在用户询问时给出。
适用场景
- 需要让官方 android CLI 指向 KMP 项目的 Android target。
- 判断某构建/部署/模拟器/SDK 任务属于官方 android-cli 命令面,还是属于 KMP 专项技能(feature-scaffold、ci-github-actions)。
- 将 CLI 的稳定命令接入现有的 Android/iOS/Desktop/Web CI 测试矩阵。
- 触发关键词包括:android cli、android-cli、android init、android skills add、create android virtual device、AVD from terminal、start emulator cli、android run apk、install apk cli、android sdk install、build and run android app、deploy to emulator、run on device from terminal、launch android app terminal、run KMP android target、test android target locally 等。
限制
- 命令标志与参数以上游 SKILL.md 当前版本为准;本技能不控制上游发布节奏,使用前需重新核对。文中给出的 CI 示例(emulator create/sdk install 的参数形态)为示意,未针对特定 CLI 版本验证。
- android create 不适用于已搭建的 KMP 项目。
- android studio * 需运行中且版本兼容的 Android Studio。
- 文中提及的更新记录显示,早期草稿曾编造 create --template-name=、skills add --all 等不存在的标志,并曾错误声称不存在官方技能;当前版本已在 2026-07-19 对照上游更正。
相关技能
kotlin-multiplatform-feature-scaffold(项目结构与 Android target 添加)、kotlin-multiplatform-ci-github-actions(CI 冒烟任务归属)、kotlin-multiplatform-roborazzi(无 Studio 时的渲染测试回退)、kotlin-multiplatform-audit(变更后校验六层模块契约)。