developer-device-platform-device-run

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Developer 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. The
gcloud beta device-run
commands might change without notice.
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 devicesThis skill (
android-executable
)
Run an Android instrumentation test APK on remote devicesThis skill (
instrumentation
)
Reserve a device, connect with adb, stream the screen
developer-device-platform-basics
Extend or cancel an interactive device lease
developer-device-platform-basics
Work with a device connected over USBNeither (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-executable
)
在远程设备上运行 Android instrumentation 测试 APK此 skill(
instrumentation
)
预留设备、通过 adb 连接、串流屏幕
developer-device-platform-basics
延长或取消交互式设备租约
developer-device-platform-basics
处理通过 USB 连接的设备均不使用(非 DDP)
以下设置步骤已经完整给出;此 skill 的身份验证、项目选择和 API 启用均不依赖其他 skill。

Requests this skill does not handle

此 skill 不处理的请求

For interactive use (reserve a device, adb, screen streaming, leases):
  • If
    developer-device-platform-basics
    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.
  • If
    developer-device-platform-basics
    is not installed:
    reply in a single message without calling any tools (no commands, searches, file reads or scheduling), then stop:
    1. Say that Device Run is for non-interactive batch jobs, so you will not submit a Device Run session.
    2. Point the user to an interactive Device Streaming reservation with the
      developer-device-platform-basics
      skill (or https://docs.cloud.google.com/device-streaming/docs/overview.md.txt), and suggest installing the skill.
    3. Warn that an interactive reservation is also billed to the active Google Cloud project.
对于交互式用途(预留设备、adb、屏幕串流、租约):
  • **如果已安装
    developer-device-platform-basics
    :**不要提交 Device Run session;改用
    developer-device-platform-basics
    ,并说明交互式预留同样会向当前项目计费。
  • **如果未安装
    developer-device-platform-basics
    :**回复一条消息,不调用任何工具(不执行命令、搜索、文件读取或调度),然后停止:
    1. 说明 Device Run 用于非交互式批处理作业,因此不会提交 Device Run session。
    2. 引导用户使用
      developer-device-platform-basics
      skill 进行交互式 Device Streaming 预留(或参阅 https://docs.cloud.google.com/device-streaming/docs/overview.md.txt),并建议安装该 skill。
    3. 提醒交互式预留同样会向当前 Google Cloud 项目计费。

Keep answers fast

保持回复快速

Prefer this skill and
gcloud beta device-run ... --help
over broad web searches for Device Run syntax. If
gcloud
or the
beta
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.
对于 Device Run 语法,优先使用此 skill 和
gcloud beta device-run ... --help
,而不是进行宽泛的 Web 搜索。如果未安装
gcloud
或
beta
component,请回退到官方文档:https://docs.cloud.google.com/developer-device-platform/device-run.md.txt 和 https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run。对于试运行,请展示命令而不要执行。

Usage Attribution

使用归属(Usage Attribution)

MUST READ: Before executing any
gcloud
, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.
必须阅读:在执行任何
gcloud
、REST API 或 MCP 命令之前,你必须阅读并遵循使用归属(Usage Attribution)中的说明。

Setup

设置

Run these checks once per environment. Do not assume tools are installed, and do not install or update software without the user's approval.
  1. 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/null
    If gcloud is missing, point the user to https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt. If the
    beta
    component or the Device Run commands are missing, ask the user before running
    gcloud components install beta
    or
    gcloud components update
    .
  2. Authentication: Check the active account. On a Compute Engine or other remote VM, the active account may be the VM's default service account (
    ...@...iam.gserviceaccount.com
    ), which often lacks the scopes Device Run and billing calls need (
    No service account scopes specified
    ). If there is no active account, or only such a service account, ask the user to sign in.
    --update-adc
    also updates Application Default Credentials in the same flow; add
    --no-launch-browser
    in SSH or remote terminals:
    bash
    gcloud auth list --filter=status:ACTIVE --format="value(account)"
    gcloud auth login --update-adc
  3. 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
  4. 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)"
  5. Enable the Device Run API (if not already enabled; ask first):
    bash
    gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}"
  6. IAM roles: The user needs
    roles/devicerun.admin
    ,
    roles/serviceusage.serviceUsageConsumer
    and
    roles/viewer
    on the project. To read inputs from a bucket in another project, grant the DDP service agent
    roles/storage.objectViewer
    on that bucket (see https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt).
  7. Bucket: Sessions store inputs and outputs in Cloud Storage. Without
    --bucket-name
    , gcloud uses or creates
    gs://${PROJECT_ID}-devicerun
    . For project IDs that contain
    :
    ,
    .
    or
    google
    , gcloud replaces them (with
    -
    ,
    -
    and
    elgoog
    ) before adding
    -devicerun
    ; read the actual bucket from the
    Result files
    URI printed by
    submit
    or
    describe
    . A bucket named explicitly with
    --bucket-name
    MUST already exist. Pass the bucket name only (no
    gs://
    , no path). Inputs and outputs under
    gs://<bucket>/automation/
    are kept until you delete them or a Cloud Storage lifecycle rule expires them, and storage is billed meanwhile.
每个环境运行一次以下检查。不要假定工具已安装,也不得在未获得用户批准的情况下安装或更新软件。
  1. 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。如果缺少
    beta
    component 或 Device Run 命令,在运行
    gcloud components install beta
    或
    gcloud components update
    之前,询问用户。
  2. 身份验证:检查当前账户。在 Compute Engine 或其他远程 VM 上,当前账户可能是 VM 的默认 service account(
    ...@...iam.gserviceaccount.com
    ),而该账户通常缺少 Device Run 和计费调用所需的 scopes(
    No service account scopes specified
    )。如果不存在当前账户,或者只有这类 service account,请让用户登录。
    --update-adc
    也会在同一流程中更新 Application Default Credentials;在 SSH 或远程终端中添加
    --no-launch-browser
    :
    bash
    gcloud auth list --filter=status:ACTIVE --format="value(account)"
    gcloud auth login --update-adc
  3. 项目:使用用户当前的项目,或用户指定的项目。绝不硬编码项目,也不要在未经询问的情况下更改当前项目。
    bash
    export PROJECT_ID=$(gcloud config get project)
    # Only if the user asks to switch:
    gcloud config set project PROJECT_ID
  4. 计费:Device Run 会向项目计费。检查是否已启用计费;如果未启用,请停止并告知用户。
    bash
    gcloud billing projects describe "${PROJECT_ID}" \
      --format="value(billingEnabled)"
  5. 启用 Device Run API(如果尚未启用;请先询问):
    bash
    gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}"
  6. IAM 角色:用户需要拥有项目上的
    roles/devicerun.admin
    、
    roles/serviceusage.serviceUsageConsumer
    和
    roles/viewer
    角色。若要从另一个项目的 bucket 读取输入,请为该 bucket 授予 DDP service agent
    roles/storage.objectViewer
    角色(请参阅 https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt)。
  7. Bucket:Session 会将输入和输出存储在 Cloud Storage 中。如果未指定
    --bucket-name
    ,gcloud 会使用或创建
    gs://${PROJECT_ID}-devicerun
    。对于包含
    :
    、
    .
    或
    google
    的项目 ID,gcloud 会在追加
    -devicerun
    前将其分别替换为
    -
    、
    -
    和
    elgoog
    ;请从
    submit
    或
    describe
    打印的
    Result files
    URI 中读取实际 bucket 名称。通过
    --bucket-name
    显式指定的 bucket 必须已经存在。只需传入 bucket 名称(不要带
    gs://
    ,也不要带路径)。
    gs://<bucket>/automation/
    下的输入和输出会一直保留,直到你将其删除或 Cloud Storage 生命周期规则使其过期;在此期间仍会产生存储费用。

Core workflow

核心工作流

  1. Pick devices. Users usually name devices the way they are sold ("Pixel 10", "Galaxy S22"), while
    --device
    needs a catalog ID such as
    frankel-36
    (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).
  2. Stage inputs.
    --executable
    ,
    --test
    ,
    --target-app
    and the source side of
    --other-files-to-push
    accept
    gs://
    paths or local paths. Local files are uploaded automatically into a fresh
    automation/inputs/<timestamp>/
    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 by
    gs://
    path.
  3. Confirm cost. Explicit user confirmation required. Device Run sessions are billed to the active Google Cloud project. Before submitting, tell the user the project (
    ${PROJECT_ID}
    ), 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.
  4. 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.
  5. Wait. For runs longer than a few minutes, submit with
    --async
    and follow session_lifecycle.md.
  6. Collect results. Download and map artifacts to devices with results.md.
  7. Report one row per device: device ID, job folder (
    job-NNN
    ), result, key outputs, and the
    gs://
    path of the session folder. Call out failed, timed-out or cancelled jobs explicitly instead of dropping them.
  1. 选择设备。 用户通常会按销售名称指定设备("Pixel 10"、"Galaxy S22"),而
    --device
    需要目录 ID,例如
    frankel-36
    (代号 + Android API level)。使用 device_selection.md 中的实时目录将名称解析为 ID;绝不要凭记忆猜测 ID。如果某款设备提供多个 Android 版本,而用户未指定版本,请列出这些版本,推荐其中一个,并让用户选择一个、多个(每个设备一个作业)或全部;绝不要擅自选择。提交前,向用户展示已解析的 ID、设备名称和 Android 版本,并明确说明你代为做出的任何其他选择(实体设备或虚拟设备、具体变体)。
  2. 准备输入。
    --executable
    、
    --test
    、
    --target-app
    以及
    --other-files-to-push
    的源文件路径均可接受
    gs://
    路径或本地路径。本地文件会自动上传到全新的
    automation/inputs/<timestamp>/
    文件夹,因此对于每次运行之间会变化的文件(脚本、刚构建的二进制文件),优先使用本地路径。将大型且重复使用的文件(模型、数据集)一次性上传到 bucket,然后通过
    gs://
    路径引用。
  3. 确认费用。必须获得用户的明确确认。 Device Run session 会向当前 Google Cloud 项目计费。提交前,告知用户
    ${PROJECT_ID}
    、设备、作业数量和超时时间,提醒会产生费用,然后停止,直到他们批准。每一次展示提交命令的回复都必须包含此计费警告,即使你只是在解释步骤,或者用户会自行运行该命令。
  4. 提交。 选择提交类型:
    • 原生可执行文件或 shell 脚本:请参阅 android_executable.md。
    • Instrumentation 测试 APK:请参阅 instrumentation.md。
    • 对每台设备使用同一二进制文件,但采用多种配置(不同的 flags、输入或环境变量):请参阅 multi_config_runs.md。
  5. 等待。 对于耗时超过几分钟的运行,使用
    --async
    提交,并遵循 session_lifecycle.md。
  6. 收集结果。 按照 results.md 下载产物并将其映射到设备。
  7. 报告。 每台设备报告一行:设备 ID、作业文件夹(
    job-NNN
    )、结果、关键输出,以及 session 文件夹的
    gs://
    路径。明确指出失败、超时或已取消的作业,不要将其省略。

Rules

规则

  • Always set the timeout.
    --executable-timeout
    (or
    --instrumentation-timeout
    ) defaults to
    5m
    ; the valid range is
    1m
    to
    3h
    . Estimate the run time and set it explicitly.
  • Arguments are comma-separated. Each element of
    --executable-args
    becomes one argument. Rewrite space-separated command lines. If a value contains a comma, use the
    ^SEP^
    prefix (see android_executable.md).
  • No shell in the direct call. With a binary as
    --executable
    there is no shell: set environment variables with
    --executable-env-vars
    , not
    export
    .
  • Do not overwrite shared inputs. DDP fetches inputs when a job starts. Never overwrite a
    gs://
    script or binary that a pending session uses; use local paths (auto-uploaded) or a unique
    gs://
    path per run.
  • Label sessions with
    --labels
    (for example
    purpose=smoke,build=1234
    ) so they are easy to find later.
  • 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
    ,
    deviceSessions
    ) to run batch jobs; that is for interactive leases.
  • 始终设置超时。
    --executable-timeout
    (或
    --instrumentation-timeout
    )默认值为
    5m
    ;有效范围为
    1m
    到
    3h
    。估算运行时间并显式设置。
  • 参数以逗号分隔。
    --executable-args
    的每个元素都会成为一个参数。请改写以空格分隔的命令行。如果某个值包含逗号,请使用
    ^SEP^
    前缀(请参阅 android_executable.md)。
  • 直接调用时不使用 shell。 将二进制文件作为
    --executable
    时不会使用 shell:请使用
    --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
    、
    deviceSessions
    )运行批处理作业;该 API 用于交互式租约。

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:常见故障。