Control real Android and iOS devices, run apps, take screenshots, and execute on-device inference via Ghost in the Droid MCP server (62 tools).
编程
Devicebase
试用Devicebase CLI — cross-platform Go CLI for remote Android, HarmonyOS, and iOS device control via HTTP API. Supports tap, swipe, text input, app launching, screenshots, UI hierarchy inspection, and more.
它能做什么
Devicebase CLI — cross-platform Go CLI for remote Android, HarmonyOS, and iOS device control via HTTP API. Supports tap, swipe, text input, app launching, screenshots, UI hierarchy inspection, and more.
技能文档
Devicebase CLI
A cross-platform Go CLI tool for remote device control. Supports Android, HarmonyOS, and iOS devices. Capabilities include tap, swipe, text input, app launching, screenshots, UI hierarchy inspection, and device information retrieval.
When to Activate
- Building AI agents or automation scripts that interact with mobile devices
- Developing mobile app testing pipelines
- Creating remote device control workflows
- Implementing deviceFarm or mobile CI/CD integrations
- Any task requiring programmatic mobile device interaction
Quick Reference
Command Pattern
# Commands requiring device serial
devicebase -s [args]
# Global commands (no serial required)
devicebase list-devices [flags]
All Commands
| Command | Args | Description |
|---|---|---|
tap | , | Single tap at coordinates |
double-tap | , | Double tap at coordinates |
long-press | , | Long press at coordinates |
swipe | ,,, | Swipe from start to end point |
back | (none) | Press back button |
home | (none) | Press home button |
launch-app | `` | Launch app by package name/bundle ID |
current-app | (none) | Get foreground app identifier |
input | `` | Input text into focused field |
clear-text | (none) | Clear text in focused field |
device-info | (none) | Get device hardware and status info |
dump-hierarchy | (none) | Get UI accessibility tree as JSON |
screenshot | (none) | Capture screen (stdout or file) |
list-devices | (none) | List all available devices |
Environment Setup
Both environment variables are required. The CLI exits with code 1 if either is missing.
# Install Devicebase CLI on Linux/MacOS (if not already installed)
which devicebase || curl -fsSL https://downloads.devicebase.cn/cli/install.sh | bash
# Install Devicebase CLI on Windows (if not already installed)
powershell -c "irm https://downloads.devicebase.cn/cli/install.ps1 | iex"
# Export API key to environment variable on Linux/MacOS (recommended for repeated use)
export DEVICEBASE_API_KEY="your_api_key"
# Export API key to environment variable on Windows (recommended for repeated use)
$env:DEVICEBASE_API_KEY = "your_api_key"
# Or inline (for one-off commands)
DEVICEBASE_API_KEY=your_api_key \
devicebase -s
| Variable | Required | Description |
|---|---|---|
DEVICEBASE_API_KEY | Yes | APK key for authentication. Sent as Authorization: Bearer on every request. Get your API key from https://www.devicebase.cn/ |
Global Flags
| Flag | Short | Required | Description |
|---|---|---|---|
--serial | -s | Yes | Device serial number. Must be specified for every command. |
--help | -h | No | Show help for any command or subcommand. |
--version | No | Show CLI version. |
Missing serial produces:
Error: required flag(s) "--serial" not set
Device Listing
list-devices
List all available devices with their serial numbers, states, and basic info.
devicebase list-devices
# Filter by keyword (brand/model/serial/name)
devicebase list-devices --keyword "iPhone"
# Filter by state (busy/free/offline)
devicebase list-devices --state free
# Combine filters
devicebase list-devices --keyword "Samsung" --state busy
| Flag | Short | Default | Description |
|---|---|---|---|
--keyword | -k | (none) | Filter by brand, model, serial, or name |
--state | (none) | Filter by device state: busy, free, or offline |
Common workflows:
# Find an available device for testing
devicebase list-devices --state free
# Find a specific device by model
devicebase list-devices --keyword "Pixel"
# Check all iOS devices
devicebase list-devices --keyword "iPhone"
Touch Interactions
All touch commands use pixel coordinates. Format: x,y (horizontal,vertical).
tap
Single tap at coordinates.
devicebase -s tap 100,200
double-tap
Double tap at coordinates.
devicebase -s double-tap 540,960
long-press
Long press (touch and hold) at coordinates.
devicebase -s long-press 200,400
swipe
Swipe from one point to another.
devicebase -s swipe 100,200,300,400
# Format: x1,y1,x2,y2 (start point to end point)
Common workflows:
# Tap center-bottom of a 1080x1920 screen
devicebase -s tap 540,1800
# Pull to refresh (swipe up)
devicebase -s swipe 540,1600,540,200
# Long press to trigger context menu
devicebase -s long-press 540,960
Navigation
back
Press the back button. Use to navigate back, dismiss dialogs, or close keyboards.
devicebase -s back
home
Press the home button to return to the home screen.
devicebase -s home
Workflow:
# Navigate back twice
devicebase -s back
devicebase -s back
# Go home then launch an app
devicebase -s home
devicebase -s launch-app com.android.settings
App Management
launch-app
Launch an application by its package name (Android/HarmonyOS) or bundle ID (iOS).
# Android
devicebase -s launch-app com.android.settings
# iOS
devicebase -s launch-app com.apple.Maps
# HarmonyOS
devicebase -s launch-app com.huawei.systemmanager
Empty app name is rejected with exit code 1:
Error: app_name cannot be empty
current-app
Get the identifier of the currently foreground app.
devicebase -s current-app
Workflow:
# Launch and verify
devicebase -s launch-app com.android.settings
sleep 1
devicebase -s current-app
# Output: com.android.settings
# Conditional action
CURRENT=$(devicebase -s current-app)
echo "Current app: $CURRENT"
Text Input
input
Type text into the currently focused text field. The device must have a text field focused (tap it first).
devicebase -s input "Hello World"
Quote text containing spaces or special characters:
devicebase -s input "user@example.com"
devicebase -s input "Password123!"
clear-text
Clear all text in the focused text field.
devicebase -s clear-text
Workflow:
# Fill a search field
devicebase -s tap 540,100 # tap search box
devicebase -s input "android" # type query
devicebase -s tap 540,200 # tap search button
# Correct a typo
devicebase -s input "hello"
devicebase -s clear-text
devicebase -s input "world"
# Login form
devicebase -s tap 540,400
devicebase -s input "myuser"
devicebase -s tap 540,600
devicebase -s input "mypassword"
devicebase -s tap 900,750
Device Information
device-info
Retrieve device information: status, hardware, connection state, OS version, screen resolution, battery, etc.
devicebase -s device-info
dump-hierarchy
Dump the current UI accessibility tree as JSON. Returns nodes with attributes like resource-id, text, class, bounds, clickable, enabled.
devicebase -s dump-hierarchy
Use cases:
- Inspect UI layout to find element coordinates
- Verify UI state after interactions
- Build selectors for automation
screenshot
Capture the device screen as an image.
# Save to file
devicebase -s screenshot -o screen.png
# Output to stdout (for piping)
devicebase -s screenshot > screen.png
# Output to stdout (for base64)
devicebase -s screenshot | base64
| Flag | Short | Default | Description |
|---|---|---|---|
--output | -o | stdout | Output file path. |
Workflow:
# Capture state for analysis
devicebase -s screenshot -o /tmp/state.png
# Find a button's coordinates from hierarchy
devicebase -s dump-hierarchy | jq '.nodes[] | select(.text == "Submit") | .bounds'
# Full inspection pipeline
devicebase -s screenshot -o /tmp/screen.png
devicebase -s dump-hierarchy > /tmp/hierarchy.json
devicebase -s device-info > /tmp/device.json
AI Agent Integration
Sequential Actions
devicebase -s launch-app com.android.settings
sleep 2
devicebase -s tap 540,500
sleep 1
devicebase -s input "Wi-Fi"
Conditional Execution
CURRENT=$(devicebase -s current-app)
if [ "$CURRENT" = "com.android.settings" ]; then
devicebase -s back
else
devicebase -s launch-app com.android.settings
fi
Hierarchy-Driven Navigation
# Find and tap a button from the hierarchy
devicebase -s dump-hierarchy | jq -r '
.nodes[]
| select(.text == "Continue" and .enabled == true)
| .bounds
' | while read -r bounds; do
# Parse bounds [x,y][x,y] and tap center
devicebase -s tap 540,960
done
Multi-Device Orchestration
# Control multiple devices in parallel
devicebase -s device1_serial tap 100,200 &
devicebase -s device2_serial tap 300,400 &
devicebase -s device3_serial tap 500,600 &
wait
Error-Aware Execution
if devicebase -s launch-app com.example.app; then
echo "App launched successfully"
else
echo "Failed to launch app"
devicebase -s screenshot -o /tmp/error.png
exit 1
fi
Error Reference
CLI Errors
| Error | Cause | Fix |
|---|---|---|
required flag(s) "--serial" not set | Missing -s | Add -s |
invalid point format "x y", expected x,y | Wrong separator | Use comma: 100,200 |
invalid bounds format "...", expected x1,y1,x2,y2 | Wrong format | Use 4 comma-separated ints |
app_name cannot be empty | Empty string to launch-app | Provide valid package/bundle ID |
unknown command | Typo in subcommand | Check command name |
Environment Errors
| Error | Cause | Fix |
|---|---|---|
DEVICEBASE_BASE_URL environment variable is not set | Missing base URL | Export DEVICEBASE_BASE_URL |
DEVICEBASE_API_KEY environment variable is not set | Missing API key | Export DEVICEBASE_API_KEY |
API error (HTTP 401): ... | Invalid/missing API key | Check DEVICEBASE_API_KEY |
API error (HTTP 404): ... | Device not found | Verify serial number and device connection |
API error (HTTP 500): ... | Server error | Check Devicebase server logs |
request failed: connection refused | Server unreachable | Verify DEVICEBASE_BASE_URL and server is running |
Critical Rules
- Always use
-s— every command requires the device serial. - Set both environment variables —
DEVICEBASE_BASE_URLandDEVICEBASE_API_KEYbefore running. - Use comma-separated coordinates —
100,200, NOT100 200. - Quote text with spaces —
input "Hello World". - Screenshot defaults to stdout — use
-o fileto save to a file. - Exit code 1 on any error — both bad input and API failures cause non-zero exit.
相关技能
Android设备远程控制与屏幕理解引擎,基于uiautomator2+FastMCP,支持多设备连接池+心跳检测、UI层级解析(dump_hierarchy核心)、元素查找与点击、触控操作(点击/滑动/输入)、APP启停、消息收发、微信专用操作、AutoGLM视觉分析。触发: Android设备操作/微信自动化/屏幕理解/UI自动化/多设备管理
Use the longarm Android remote-control app through its HTTP API or MCP server. Trigger when the user asks to remotely tap, long-press, swipe, scroll, pinch,...
AI 驱动的 Android 自动化 — 截屏、点击、滑动、输入、启动应用、UI 识别、多设备群控 | Android automation via ADB, screen capture, tap, swipe, type text, app control, multi-device, phone RPA, adb bot
多终端设备自动化与AI视觉理解引擎,支持Android(uiautomator2)设备控制、微信/闲鱼/抖音场景自动化、AutoGLM视觉理解、智能路由(规则/AI/混合)、规则引擎与自学习、多终端协同调度、9平台内容发布。触发: 设备操作/微信发消息/闲鱼发布/抖音发布/多平台内容分发/AI视觉分析/规则优化
通过 HTTP 或 WebSocket 控制活跃的远程 Chrome 会话,支持 DOM 自动化与 VNC 桌面操作。