developer-device-platform-device-run
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeveloper Device Platform: Device Run
Developer Device Platform: Device Run
Device Run executes a job on remote DDP devices and returns its artifacts (logs,
pulled files) to a Cloud Storage bucket. One session fans out to one job per
requested device.
[!WARNING] Developer Device Platform (DDP) is currently in Preview. Thecommands might change without notice.gcloud beta device-run
Device Run 会在远程 DDP 设备上执行作业,并将产物(日志、拉取的文件)返回到 Cloud Storage bucket。一个 session 会为每个请求的设备分派一个作业。
[!WARNING] Developer Device Platform (DDP) 目前处于 Preview 阶段。命令可能会在未经通知的情况下发生变化。gcloud beta device-run
When to use this skill
何时使用此 skill
| The user wants to... | Use |
|---|---|
| Run a native binary or shell script on remote devices | This skill ( |
| Run an Android instrumentation test APK on remote devices | This skill ( |
| Reserve a device, connect with adb, stream the screen | |
| Extend or cancel an interactive device lease | |
| Work with a device connected over USB | Neither (not DDP) |
The setup below is complete; this skill doesn't depend on another skill for
authentication, project selection or API enablement.
| 用户希望…… | 使用 |
|---|---|
| 在远程设备上运行原生二进制文件或 shell 脚本 | 此 skill( |
| 在远程设备上运行 Android instrumentation 测试 APK | 此 skill( |
| 预留设备、通过 adb 连接、串流屏幕 | |
| 延长或取消交互式设备租约 | |
| 处理通过 USB 连接的设备 | 均不使用(非 DDP) |
以下设置步骤已经完整给出;此 skill 的身份验证、项目选择和 API 启用均不依赖其他 skill。
Requests this skill does not handle
此 skill 不处理的请求
For interactive use (reserve a device, adb, screen streaming, leases):
- If is installed: do not submit a Device Run session; switch to
developer-device-platform-basics, and note that interactive reservations are also billed to the active project.developer-device-platform-basics - If is not installed: reply in a single message without calling any tools (no commands, searches, file reads or scheduling), then stop:
developer-device-platform-basics- Say that Device Run is for non-interactive batch jobs, so you will not submit a Device Run session.
- Point the user to an interactive Device Streaming reservation with the
skill (or https://docs.cloud.google.com/device-streaming/docs/overview.md.txt), and suggest installing the skill.
developer-device-platform-basics - Warn that an interactive reservation is also billed to the active Google Cloud project.
对于交互式用途(预留设备、adb、屏幕串流、租约):
- **如果已安装 :**不要提交 Device Run session;改用
developer-device-platform-basics,并说明交互式预留同样会向当前项目计费。developer-device-platform-basics - **如果未安装 :**回复一条消息,不调用任何工具(不执行命令、搜索、文件读取或调度),然后停止:
developer-device-platform-basics- 说明 Device Run 用于非交互式批处理作业,因此不会提交 Device Run session。
- 引导用户使用 skill 进行交互式 Device Streaming 预留(或参阅 https://docs.cloud.google.com/device-streaming/docs/overview.md.txt),并建议安装该 skill。
developer-device-platform-basics - 提醒交互式预留同样会向当前 Google Cloud 项目计费。
Keep answers fast
保持回复快速
Prefer this skill and over broad web
searches for Device Run syntax. If or the component is not
installed, fall back to the official documentation at
https://docs.cloud.google.com/developer-device-platform/device-run.md.txt and
https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run. For dry
runs, show the commands instead of running them.
gcloud beta device-run ... --helpgcloudbeta对于 Device Run 语法,优先使用此 skill 和 ,而不是进行宽泛的 Web 搜索。如果未安装 或 component,请回退到官方文档:https://docs.cloud.google.com/developer-device-platform/device-run.md.txt 和 https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run。对于试运行,请展示命令而不要执行。
gcloud beta device-run ... --helpgcloudbetaUsage Attribution
使用归属(Usage Attribution)
MUST READ: Before executing any , REST API, or MCP command, you
MUST read and follow the instructions in
Usage Attribution.
gcloud必须阅读:在执行任何 、REST API 或 MCP 命令之前,你必须阅读并遵循使用归属(Usage Attribution)中的说明。
gcloudSetup
设置
Run these checks once per environment. Do not assume tools are installed, and
do not install or update software without the user's approval.
-
gcloud CLI: Check that gcloud is installed and has Device Run commands:bash
gcloud --version gcloud beta device-run sessions submit android-executable --help >/dev/nullIf gcloud is missing, point the user to https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt. If thecomponent or the Device Run commands are missing, ask the user before runningbetaorgcloud components install beta.gcloud components update -
Authentication: Check the active account. On a Compute Engine or other remote VM, the active account may be the VM's default service account (), which often lacks the scopes Device Run and billing calls need (
...@...iam.gserviceaccount.com). If there is no active account, or only such a service account, ask the user to sign in.No service account scopes specifiedalso updates Application Default Credentials in the same flow; add--update-adcin SSH or remote terminals:--no-launch-browserbashgcloud auth list --filter=status:ACTIVE --format="value(account)" gcloud auth login --update-adc -
Project: Use the user's active project, or the one they name. Never hardcode a project, and don't change the active project without asking.bash
export PROJECT_ID=$(gcloud config get project) # Only if the user asks to switch: gcloud config set project PROJECT_ID -
Billing: Device Run is billed to the project. Check that billing is enabled; if it isn't, stop and tell the user.bash
gcloud billing projects describe "${PROJECT_ID}" \ --format="value(billingEnabled)" -
Enable the Device Run API (if not already enabled; ask first):bash
gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}" -
IAM roles: The user needs,
roles/devicerun.adminandroles/serviceusage.serviceUsageConsumeron the project. To read inputs from a bucket in another project, grant the DDP service agentroles/vieweron that bucket (see https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt).roles/storage.objectViewer -
Bucket: Sessions store inputs and outputs in Cloud Storage. Without, gcloud uses or creates
--bucket-name. For project IDs that contaings://${PROJECT_ID}-devicerun,:or., gcloud replaces them (withgoogle,-and-) before addingelgoog; read the actual bucket from the-devicerunURI printed byResult filesorsubmit. A bucket named explicitly withdescribeMUST already exist. Pass the bucket name only (no--bucket-name, no path). Inputs and outputs undergs://are kept until you delete them or a Cloud Storage lifecycle rule expires them, and storage is billed meanwhile.gs://<bucket>/automation/
每个环境运行一次以下检查。不要假定工具已安装,也不得在未获得用户批准的情况下安装或更新软件。
-
gcloud CLI:检查是否已安装 gcloud 且具备 Device Run 命令:bash
gcloud --version gcloud beta device-run sessions submit android-executable --help >/dev/null如果缺少 gcloud,请引导用户访问 https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt。如果缺少component 或 Device Run 命令,在运行beta或gcloud components install beta之前,询问用户。gcloud components update -
身份验证:检查当前账户。在 Compute Engine 或其他远程 VM 上,当前账户可能是 VM 的默认 service account(),而该账户通常缺少 Device Run 和计费调用所需的 scopes(
...@...iam.gserviceaccount.com)。如果不存在当前账户,或者只有这类 service account,请让用户登录。No service account scopes specified也会在同一流程中更新 Application Default Credentials;在 SSH 或远程终端中添加--update-adc:--no-launch-browserbashgcloud auth list --filter=status:ACTIVE --format="value(account)" gcloud auth login --update-adc -
项目:使用用户当前的项目,或用户指定的项目。绝不硬编码项目,也不要在未经询问的情况下更改当前项目。bash
export PROJECT_ID=$(gcloud config get project) # Only if the user asks to switch: gcloud config set project PROJECT_ID -
计费:Device Run 会向项目计费。检查是否已启用计费;如果未启用,请停止并告知用户。bash
gcloud billing projects describe "${PROJECT_ID}" \ --format="value(billingEnabled)" -
启用 Device Run API(如果尚未启用;请先询问):bash
gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}" -
IAM 角色:用户需要拥有项目上的、
roles/devicerun.admin和roles/serviceusage.serviceUsageConsumer角色。若要从另一个项目的 bucket 读取输入,请为该 bucket 授予 DDP service agentroles/viewer角色(请参阅 https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt)。roles/storage.objectViewer -
Bucket:Session 会将输入和输出存储在 Cloud Storage 中。如果未指定,gcloud 会使用或创建
--bucket-name。对于包含gs://${PROJECT_ID}-devicerun、:或.的项目 ID,gcloud 会在追加google前将其分别替换为-devicerun、-和-;请从elgoog或submit打印的describeURI 中读取实际 bucket 名称。通过Result files显式指定的 bucket 必须已经存在。只需传入 bucket 名称(不要带--bucket-name,也不要带路径)。gs://下的输入和输出会一直保留,直到你将其删除或 Cloud Storage 生命周期规则使其过期;在此期间仍会产生存储费用。gs://<bucket>/automation/
Core workflow
核心工作流
-
Pick devices. Users usually name devices the way they are sold ("Pixel 10", "Galaxy S22"), whileneeds a catalog ID such as
--device(codename + Android API level). Resolve names to IDs from the live catalog with device_selection.md; never guess an ID from memory. If a device is offered on several Android versions and the user didn't name one, list the versions, recommend one, and let the user pick one, several (one job each) or all; never pick silently. Before submitting, show the user the resolved ID, the device name and the Android version, and call out any other choice you made for them (physical vs virtual, variant).frankel-36 -
Stage inputs.,
--executable,--testand the source side of--target-appaccept--other-files-to-pushpaths or local paths. Local files are uploaded automatically into a freshgs://folder, so prefer local paths for files that change between runs (scripts, freshly built binaries). Upload large, reused files (models, datasets) to the bucket once and reference them byautomation/inputs/<timestamp>/path.gs:// -
Confirm cost. Explicit user confirmation required. Device Run sessions are billed to the active Google Cloud project. Before submitting, tell the user the project (), the devices, the number of jobs, and the timeout, warn that this incurs charges, and STOP until they approve. Include this billing warning in every answer that shows a submit command, even when you only explain the steps or the user will run the command themselves.
${PROJECT_ID} -
Submit. Pick the submit type:
- Native executable or shell script: see android_executable.md.
- Instrumentation test APK: see instrumentation.md.
- Same binary with several configurations (different flags, inputs or environment variables) per device: see multi_config_runs.md.
-
Wait. For runs longer than a few minutes, submit withand follow session_lifecycle.md.
--async -
Collect results. Download and map artifacts to devices with results.md.
-
Report one row per device: device ID, job folder (), result, key outputs, and the
job-NNNpath of the session folder. Call out failed, timed-out or cancelled jobs explicitly instead of dropping them.gs://
-
选择设备。 用户通常会按销售名称指定设备("Pixel 10"、"Galaxy S22"),而需要目录 ID,例如
--device(代号 + Android API level)。使用 device_selection.md 中的实时目录将名称解析为 ID;绝不要凭记忆猜测 ID。如果某款设备提供多个 Android 版本,而用户未指定版本,请列出这些版本,推荐其中一个,并让用户选择一个、多个(每个设备一个作业)或全部;绝不要擅自选择。提交前,向用户展示已解析的 ID、设备名称和 Android 版本,并明确说明你代为做出的任何其他选择(实体设备或虚拟设备、具体变体)。frankel-36 -
准备输入。、
--executable、--test以及--target-app的源文件路径均可接受--other-files-to-push路径或本地路径。本地文件会自动上传到全新的gs://文件夹,因此对于每次运行之间会变化的文件(脚本、刚构建的二进制文件),优先使用本地路径。将大型且重复使用的文件(模型、数据集)一次性上传到 bucket,然后通过automation/inputs/<timestamp>/路径引用。gs:// -
确认费用。必须获得用户的明确确认。 Device Run session 会向当前 Google Cloud 项目计费。提交前,告知用户、设备、作业数量和超时时间,提醒会产生费用,然后停止,直到他们批准。每一次展示提交命令的回复都必须包含此计费警告,即使你只是在解释步骤,或者用户会自行运行该命令。
${PROJECT_ID} -
提交。 选择提交类型:
- 原生可执行文件或 shell 脚本:请参阅 android_executable.md。
- Instrumentation 测试 APK:请参阅 instrumentation.md。
- 对每台设备使用同一二进制文件,但采用多种配置(不同的 flags、输入或环境变量):请参阅 multi_config_runs.md。
-
等待。 对于耗时超过几分钟的运行,使用提交,并遵循 session_lifecycle.md。
--async -
收集结果。 按照 results.md 下载产物并将其映射到设备。
-
报告。 每台设备报告一行:设备 ID、作业文件夹()、结果、关键输出,以及 session 文件夹的
job-NNN路径。明确指出失败、超时或已取消的作业,不要将其省略。gs://
Rules
规则
- Always set the timeout. (or
--executable-timeout) defaults to--instrumentation-timeout; the valid range is5mto1m. Estimate the run time and set it explicitly.3h - Arguments are comma-separated. Each element of becomes one argument. Rewrite space-separated command lines. If a value contains a comma, use the
--executable-argsprefix (see android_executable.md).^SEP^ - No shell in the direct call. With a binary as there is no shell: set environment variables with
--executable, not--executable-env-vars.export - Do not overwrite shared inputs. DDP fetches inputs when a job starts.
Never overwrite a script or binary that a pending session uses; use local paths (auto-uploaded) or a unique
gs://path per run.gs:// - Label sessions with (for example
--labels) so they are easy to find later.purpose=smoke,build=1234 - Poll politely. Never poll in a tight loop; poll every 30 to 60 seconds and report progress (see session_lifecycle.md).
- Cancel on request. If the user wants to stop, cancel the session (see session_lifecycle.md) and tell the user it was cancelled.
- Do not use the Device Streaming API (,
devicestreaming.googleapis.com) to run batch jobs; that is for interactive leases.deviceSessions
- 始终设置超时。 (或
--executable-timeout)默认值为--instrumentation-timeout;有效范围为5m到1m。估算运行时间并显式设置。3h - 参数以逗号分隔。 的每个元素都会成为一个参数。请改写以空格分隔的命令行。如果某个值包含逗号,请使用
--executable-args前缀(请参阅 android_executable.md)。^SEP^ - 直接调用时不使用 shell。 将二进制文件作为 时不会使用 shell:请使用
--executable设置环境变量,而不是使用--executable-env-vars。export - 不要覆盖共享输入。 DDP 会在作业开始时获取输入。绝不覆盖待处理 session 正在使用的 脚本或二进制文件;请使用本地路径(自动上传)或每次运行唯一的
gs://路径。gs:// - 为 session 添加标签。 使用 (例如
--labels),以便以后轻松查找。purpose=smoke,build=1234 - 合理轮询。 绝不进行紧密循环轮询;每 30 到 60 秒轮询一次并报告进度(请参阅 session_lifecycle.md)。
- 按请求取消。 如果用户希望停止,请取消 session(请参阅 session_lifecycle.md),并告知用户已取消。
- 不要使用 Device Streaming API(、
devicestreaming.googleapis.com)运行批处理作业;该 API 用于交互式租约。deviceSessions
Reference index
参考索引
- device_selection.md: map device names such as "Pixel 10" to catalog IDs, OS versions, physical vs virtual.
- android_executable.md: flags, direct call, shared libraries, script as executable.
- instrumentation.md: APK tests, sharding, test targets.
- session_lifecycle.md: sync vs async, wait, describe, cancel, status and result types.
- results.md: bucket layout, job-to-device mapping, logs.
- multi_config_runs.md: run the same binary with several configurations per device.
- troubleshooting.md: common failures.
- device_selection.md:将 "Pixel 10" 等设备名称映射到目录 ID、操作系统版本,并区分实体设备与虚拟设备。
- android_executable.md:flags、直接调用、共享库,以及将脚本作为 executable。
- instrumentation.md:APK 测试、分片和测试目标。
- session_lifecycle.md:同步与异步、等待、describe、取消、状态和结果类型。
- results.md:bucket 布局、作业到设备的映射和日志。
- multi_config_runs.md:在每台设备上使用多种配置运行同一二进制文件。
- troubleshooting.md:常见故障。