android-device-automation by web-infra-dev/midscene-skills
npx skills add https://github.com/web-infra-dev/midscene-skills --skill android-device-automation关键规则 — 违反将导致工作流中断:
- 切勿在后台运行 midscene 命令。 每个命令必须同步运行,以便您可以在决定下一步操作之前读取其输出(尤其是截图)。后台执行会破坏截图-分析-操作的循环。
- 一次只运行一个 midscene 命令。 等待上一个命令完成,读取截图,然后决定下一个操作。切勿将多个命令链接在一起运行。
- 为每个命令预留足够的完成时间。 Midscene 命令涉及 AI 推理和屏幕交互,可能比典型的 shell 命令耗时更长。一个典型命令大约需要 1 分钟;复杂的
act命令可能需要更长时间。- 在结束前务必报告任务结果。 完成自动化任务后,您必须主动向用户总结结果——包括找到的关键数据、完成的动作、拍摄的截图以及任何相关发现。切勿在最后一个自动化步骤后默默结束;用户期望在单次交互中获得完整的回应。
使用 npx @midscene/android@1 自动化 Android 设备。每个 CLI 命令直接对应一个 MCP 工具——您(AI 代理)充当大脑,根据截图决定采取哪些操作。
Midscene 需要具备强大视觉基础能力的模型。必须配置以下环境变量——可以作为系统环境变量,也可以在当前工作目录的 .env 文件中配置(Midscene 会自动加载 .env):
MIDSCENE_MODEL_API_KEY="your-api-key"
MIDSCENE_MODEL_NAME="model-name"
MIDSCENE_MODEL_BASE_URL="https://..."
MIDSCENE_MODEL_FAMILY="family-identifier"
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
示例:Gemini (Gemini-3-Flash)
MIDSCENE_MODEL_API_KEY="your-google-api-key"
MIDSCENE_MODEL_NAME="gemini-3-flash"
MIDSCENE_MODEL_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
MIDSCENE_MODEL_FAMILY="gemini"
示例:Qwen 3.5
MIDSCENE_MODEL_API_KEY="your-aliyun-api-key"
MIDSCENE_MODEL_NAME="qwen3.5-plus"
MIDSCENE_MODEL_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
MIDSCENE_MODEL_FAMILY="qwen3.5"
MIDSCENE_MODEL_REASONING_ENABLED="false"
# 如果使用 OpenRouter,请设置:
# MIDSCENE_MODEL_API_KEY="your-openrouter-api-key"
# MIDSCENE_MODEL_NAME="qwen/qwen3.5-plus"
# MIDSCENE_MODEL_BASE_URL="https://openrouter.ai/api/v1"
示例:豆包 Seed 2.0 Lite
MIDSCENE_MODEL_API_KEY="your-doubao-api-key"
MIDSCENE_MODEL_NAME="doubao-seed-2-0-lite"
MIDSCENE_MODEL_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
MIDSCENE_MODEL_FAMILY="doubao-seed"
常用模型:豆包 Seed 2.0 Lite、Qwen 3.5、智谱 GLM-4.6V、Gemini-3-Pro、Gemini-3-Flash。
如果模型未配置,请要求用户进行设置。有关支持的提供商,请参阅模型配置。
npx @midscene/android@1 connect
npx @midscene/android@1 connect --deviceId emulator-5554
npx @midscene/android@1 take_screenshot
截图后,在决定下一步操作之前,请读取保存的图像文件以了解当前屏幕状态。
使用 act 与设备交互并获取结果。它在内部自主处理所有 UI 交互——点击、输入、滚动、滑动、等待和导航——因此您应该将复杂、高级的任务作为一个整体交给它,而不是分解成小步骤。用自然语言描述您想做什么以及期望的效果:
# 具体指令
npx @midscene/android@1 act --prompt "type hello world in the search field and press Enter"
npx @midscene/android@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
# 或目标驱动指令
npx @midscene/android@1 act --prompt "open Settings and navigate to Wi-Fi settings, tell me the connected network name"
npx @midscene/android@1 disconnect
由于 CLI 命令在调用之间是无状态的,请遵循以下模式:
act 执行操作以执行所需操作或目标驱动指令。adb shell am start -n <package/activity>)。然后截图以确认应用确实在前台。只有在视觉确认后,您才应继续使用此技能进行 UI 自动化。ADB 命令比使用 midscene 导航和打开应用要快得多。"右侧的 Wi-Fi 切换开关",而不是 "那个开关"。"右上角的搜索图标"、"列表中的第三项")。act 命令:在同一应用内执行连续操作时,将它们合并到一个 act 提示中,而不是拆分成单独的命令。例如,"打开设置,点击 Wi-Fi,然后打开它" 应该是一个 act 调用,而不是三个。这减少了往返次数,避免了不必要的截图-分析周期,并且速度显著更快。示例 — 弹出菜单交互:
npx @midscene/android@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
npx @midscene/android@1 take_screenshot
示例 — 表单交互:
npx @midscene/android@1 act --prompt "fill in the username field with 'testuser' and the password field with 'pass123', then tap the Login button"
npx @midscene/android@1 take_screenshot
| 问题 | 解决方案 |
|---|---|
| 未找到 ADB | 安装 Android SDK Platform Tools:brew install android-platform-tools (macOS) 或从 developer.android.com 下载。 |
| 设备未列出 | 检查 USB 连接,确保开发者选项中已启用 USB 调试,并运行 adb devices。 |
| 设备显示 "unauthorized" | 解锁设备并接受 USB 调试授权提示。然后再次运行 adb devices。 |
| 设备显示 "offline" | 断开并重新连接 USB 线缆。运行 adb kill-server && adb start-server。 |
| 命令超时 | 设备屏幕可能已关闭或锁定。使用 adb shell input keyevent KEYCODE_WAKEUP 唤醒设备并解锁。 |
| API 密钥错误 | 检查 .env 文件是否包含 MIDSCENE_MODEL_API_KEY=<your-key>。请参阅模型配置。 |
| 目标设备错误 | 如果连接了多个设备,请在 connect 命令中使用 --deviceId <id> 标志。 |
每周安装量
585
代码仓库
GitHub 星标数
137
首次出现
2026年3月6日
安全审计
安装于
openclaw359
codex329
cursor328
opencode327
gemini-cli324
cline324
CRITICAL RULES — VIOLATIONS WILL BREAK THE WORKFLOW:
- Never run midscene commands in the background. Each command must run synchronously so you can read its output (especially screenshots) before deciding the next action. Background execution breaks the screenshot-analyze-act loop.
- Run only one midscene command at a time. Wait for the previous command to finish, read the screenshot, then decide the next action. Never chain multiple commands together.
- Allow enough time for each command to complete. Midscene commands involve AI inference and screen interaction, which can take longer than typical shell commands. A typical command needs about 1 minute; complex
actcommands may need even longer.- Always report task results before finishing. After completing the automation task, you MUST proactively summarize the results to the user — including key data found, actions completed, screenshots taken, and any relevant findings. Never silently end after the last automation step; the user expects a complete response in a single interaction.
Automate Android devices using npx @midscene/android@1. Each CLI command maps directly to an MCP tool — you (the AI agent) act as the brain, deciding which actions to take based on screenshots.
Midscene requires models with strong visual grounding capabilities. The following environment variables must be configured — either as system environment variables or in a .env file in the current working directory (Midscene loads .env automatically):
MIDSCENE_MODEL_API_KEY="your-api-key"
MIDSCENE_MODEL_NAME="model-name"
MIDSCENE_MODEL_BASE_URL="https://..."
MIDSCENE_MODEL_FAMILY="family-identifier"
Example: Gemini (Gemini-3-Flash)
MIDSCENE_MODEL_API_KEY="your-google-api-key"
MIDSCENE_MODEL_NAME="gemini-3-flash"
MIDSCENE_MODEL_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
MIDSCENE_MODEL_FAMILY="gemini"
Example: Qwen 3.5
MIDSCENE_MODEL_API_KEY="your-aliyun-api-key"
MIDSCENE_MODEL_NAME="qwen3.5-plus"
MIDSCENE_MODEL_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
MIDSCENE_MODEL_FAMILY="qwen3.5"
MIDSCENE_MODEL_REASONING_ENABLED="false"
# If using OpenRouter, set:
# MIDSCENE_MODEL_API_KEY="your-openrouter-api-key"
# MIDSCENE_MODEL_NAME="qwen/qwen3.5-plus"
# MIDSCENE_MODEL_BASE_URL="https://openrouter.ai/api/v1"
Example: Doubao Seed 2.0 Lite
MIDSCENE_MODEL_API_KEY="your-doubao-api-key"
MIDSCENE_MODEL_NAME="doubao-seed-2-0-lite"
MIDSCENE_MODEL_BASE_URL="https://ark.cn-beijing.volces.com/api/v3"
MIDSCENE_MODEL_FAMILY="doubao-seed"
Commonly used models: Doubao Seed 2.0 Lite, Qwen 3.5, Zhipu GLM-4.6V, Gemini-3-Pro, Gemini-3-Flash.
If the model is not configured, ask the user to set it up. See Model Configuration for supported providers.
npx @midscene/android@1 connect
npx @midscene/android@1 connect --deviceId emulator-5554
npx @midscene/android@1 take_screenshot
After taking a screenshot, read the saved image file to understand the current screen state before deciding the next action.
Use act to interact with the device and get the result. It autonomously handles all UI interactions internally — tapping, typing, scrolling, swiping, waiting, and navigating — so you should give it complex, high-level tasks as a whole rather than breaking them into small steps. Describe what you want to do and the desired effect in natural language:
# specific instructions
npx @midscene/android@1 act --prompt "type hello world in the search field and press Enter"
npx @midscene/android@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
# or target-driven instructions
npx @midscene/android@1 act --prompt "open Settings and navigate to Wi-Fi settings, tell me the connected network name"
npx @midscene/android@1 disconnect
Since CLI commands are stateless between invocations, follow this pattern:
act to perform the desired action or target-driven instructions.adb shell am start -n <package/activity>) before invoking any midscene commands. Then take a screenshot to confirm the app is actually in the foreground. Only after visual confirmation should you proceed with UI automation using this skill. ADB commands are significantly faster than using midscene to navigate to and open apps."the Wi-Fi toggle switch on the right side" instead of "the toggle"."the search icon at the top right", "the third item in the list").act command: When performing consecutive operations within the same app, combine them into one prompt instead of splitting them into separate commands. For example, "open Settings, tap Wi-Fi, and toggle it on" should be a single call, not three. This reduces round-trips, avoids unnecessary screenshot-analyze cycles, and is significantly faster.Example — Popup menu interaction:
npx @midscene/android@1 act --prompt "long press the message bubble and tap Delete in the popup menu"
npx @midscene/android@1 take_screenshot
Example — Form interaction:
npx @midscene/android@1 act --prompt "fill in the username field with 'testuser' and the password field with 'pass123', then tap the Login button"
npx @midscene/android@1 take_screenshot
| Problem | Solution |
|---|---|
| ADB not found | Install Android SDK Platform Tools: brew install android-platform-tools (macOS) or download from developer.android.com. |
| Device not listed | Check USB connection, ensure USB debugging is enabled in Developer Options, and run adb devices. |
| Device shows "unauthorized" | Unlock the device and accept the USB debugging authorization prompt. Then run adb devices again. |
| Device shows "offline" | Disconnect and reconnect the USB cable. Run adb kill-server && adb start-server. |
| Command timeout |
Weekly Installs
585
Repository
GitHub Stars
137
First Seen
Mar 6, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
openclaw359
codex329
cursor328
opencode327
gemini-cli324
cline324
Google Slides 演示文稿创建与共享自动化教程 - 使用 Google Workspace CLI
6,500 周安装
Angular 21 最佳实践指南:TypeScript、Signals、组件与性能优化
531 周安装
find-skills:AI代理技能搜索与安装工具,快速扩展AI助手能力
531 周安装
Spring Boot 测试模式指南:JUnit 5、Mockito、Testcontainers与切片测试
533 周安装
Clarify技能详解:AI需求澄清与结构化提问技术,提升需求明确化效率
534 周安装
OKX CEX Earn CLI:OKX交易所赚币命令行工具,管理简单赚币、双币赢、链上赚币
534 周安装
Rust CLI开发指南:领域约束、clap参数解析与最佳实践
534 周安装
actactThe device screen may be off or locked. Wake the device with adb shell input keyevent KEYCODE_WAKEUP and unlock it. |
| API key error | Check .env file contains MIDSCENE_MODEL_API_KEY=<your-key>. See Model Configuration. |
| Wrong device targeted | If multiple devices are connected, use --deviceId <id> flag with the connect command. |