1
---
2
name: developer-device-platform-device-run
3
description: >-
4
Runs automated, non-interactive jobs on remote Android devices with Developer
5
Device Platform (DDP) Device Run using `gcloud beta device-run sessions`:
6
native Android executables or shell scripts (for example CLI tools, custom
7
runners, test harnesses or benchmarks) and
8
Android instrumentation tests, on one or many devices, then waits for
9
completion and collects per-device outputs and logs. Use when running a
10
binary or test suite on remote devices without an interactive connection.
11
Don't use it for interactive device reservations, adb tunnels or screen
12
streaming (use developer-device-platform-basics), or for local devices.
13
metadata:
14
version: "1.0.0"
15
category: CloudInfrastructureAndServices
16
---
17
18
# Developer Device Platform: Device Run
19
20
Device Run executes a job on remote DDP devices and returns its artifacts (logs,
21
pulled files) to a Cloud Storage bucket. One session fans out to one job per
22
requested device.
23
24
> [!WARNING]
25
> Developer Device Platform (DDP) is currently in Preview. The
26
> `gcloud beta device-run` commands might change without notice.
27
28
## When to use this skill
29
30
The user wants to... | Use
31
:--------------------------------------------------------- | :--
32
Run a native binary or shell script on remote devices | This skill (`android-executable`)
33
Run an Android instrumentation test APK on remote devices | This skill (`instrumentation`)
34
Reserve a device, connect with adb, stream the screen | `developer-device-platform-basics`
35
Extend or cancel an interactive device lease | `developer-device-platform-basics`
36
Work with a device connected over USB | Neither (not DDP)
37
38
The setup below is complete; this skill doesn't depend on another skill for
39
authentication, project selection or API enablement.
40
41
### Requests this skill does not handle
42
43
For interactive use (reserve a device, adb, screen streaming, leases):
44
45
* **If `developer-device-platform-basics` is installed:** do not submit a
46
Device Run session; switch to `developer-device-platform-basics`, and note
47
that interactive reservations are also billed to the active project.
48
* **If `developer-device-platform-basics` is not installed:** reply in a
49
single message **without calling any tools** (no commands, searches, file
50
reads or scheduling), then stop:
51
1. Say that Device Run is for non-interactive batch jobs, so you will not
52
submit a Device Run session.
53
2. Point the user to an interactive Device Streaming reservation with the
54
`developer-device-platform-basics` skill (or
55
https://docs.cloud.google.com/device-streaming/docs/overview.md.txt),
56
and suggest installing the skill.
57
3. Warn that an interactive reservation is also billed to the active
58
Google Cloud project.
59
60
### Keep answers fast
61
62
Prefer this skill and `gcloud beta device-run ... --help` over broad web
63
searches for Device Run syntax. If `gcloud` or the `beta` component is not
64
installed, fall back to the official documentation at
65
https://docs.cloud.google.com/developer-device-platform/device-run.md.txt and
66
https://docs.cloud.google.com/sdk/gcloud/reference/beta/device-run. For dry
67
runs, show the commands instead of running them.
68
69
## Usage Attribution
70
71
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
72
MUST read and follow the instructions in
73
[Usage Attribution](references/attribution.md).
74
75
## Setup
76
77
Run these checks once per environment. Do not assume tools are installed, and
78
do not install or update software without the user's approval.
79
80
1. **gcloud CLI**: Check that gcloud is installed and has Device Run commands:
81
82
```bash
83
gcloud --version
84
gcloud beta device-run sessions submit android-executable --help >/dev/null
85
```
86
87
If gcloud is missing, point the user to
88
https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt. If the `beta`
89
component or the Device Run commands are missing, **ask the user** before
90
running `gcloud components install beta` or `gcloud components update`.
91
92
2. **Authentication**: Check the active account. On a Compute Engine or other
93
remote VM, the active account may be the VM's default service account
94
(`...@...iam.gserviceaccount.com`), which often lacks the scopes Device Run
95
and billing calls need (`No service account scopes specified`). If there is
96
no active account, or only such a service account, ask the user to sign in.
97
`--update-adc` also updates Application Default Credentials in the same
98
flow; add `--no-launch-browser` in SSH or remote terminals:
99
100
```bash
101
gcloud auth list --filter=status:ACTIVE --format="value(account)"
102
gcloud auth login --update-adc
103
```
104
105
3. **Project**: Use the user's active project, or the one they name. Never
106
hardcode a project, and don't change the active project without asking.
107
108
```bash
109
export PROJECT_ID=$(gcloud config get project)
110
# Only if the user asks to switch:
111
gcloud config set project PROJECT_ID
112
```
113
114
4. **Billing**: Device Run is billed to the project. Check that billing is
115
enabled; if it isn't, stop and tell the user.
116
117
```bash
118
gcloud billing projects describe "${PROJECT_ID}" \
119
--format="value(billingEnabled)"
120
```
121
122
5. **Enable the Device Run API** (if not already enabled; ask first):
123
124
```bash
125
gcloud services enable devicerun.googleapis.com --project="${PROJECT_ID}"
126
```
127
128
6. **IAM roles**: The user needs `roles/devicerun.admin`,
129
`roles/serviceusage.serviceUsageConsumer` and `roles/viewer` on the
130
project. To read inputs from a bucket in another project, grant the DDP
131
service agent `roles/storage.objectViewer` on that bucket (see
132
https://docs.cloud.google.com/developer-device-platform/device-run/share-storage.md.txt).
133
134
7. **Bucket**: Sessions store inputs and outputs in Cloud Storage. Without
135
`--bucket-name`, gcloud uses or creates `gs://${PROJECT_ID}-devicerun`.
136
For project IDs that contain `:`, `.` or `google`, gcloud replaces them
137
(with `-`, `-` and `elgoog`) before adding `-devicerun`; read the actual
138
bucket from the `Result files` URI printed by `submit` or `describe`. A
139
bucket named explicitly with `--bucket-name` MUST already exist. Pass the
140
bucket name only (no `gs://`, no path). Inputs and outputs under
141
`gs://<bucket>/automation/` are kept until you delete them or a Cloud
142
Storage lifecycle rule expires them, and storage is billed meanwhile.
143
144
## Core workflow
145
146
1. **Pick devices.** Users usually name devices the way they are sold ("Pixel
147
10", "Galaxy S22"), while `--device` needs a catalog ID such as
148
`frankel-36` (codename + Android API level). Resolve names to IDs from the
149
live catalog with
150
[device_selection.md](references/device_selection.md); never guess an ID
151
from memory. If a device is offered on several Android versions and the
152
user didn't name one, list the versions, recommend one, and let the user
153
pick one, several (one job each) or all; never pick silently. Before
154
submitting, show the user the resolved ID, the device name and the Android
155
version, and call out any other choice you made for them (physical vs
156
virtual, variant).
157
158
2. **Stage inputs.** `--executable`, `--test`, `--target-app` and the source
159
side of `--other-files-to-push` accept `gs://` paths or local paths. Local
160
files are uploaded automatically into a fresh
161
`automation/inputs/<timestamp>/` folder, so prefer local paths for files
162
that change between runs (scripts, freshly built binaries). Upload large,
163
reused files (models, datasets) to the bucket once and reference them by
164
`gs://` path.
165
166
3. **Confirm cost.** **Explicit user confirmation required.** Device Run
167
sessions are billed to the active Google Cloud project. Before submitting,
168
tell the user the project (`${PROJECT_ID}`), the devices, the number of
169
jobs, and the timeout, warn that this incurs charges, and STOP until they
170
approve. Include this billing warning in **every** answer that shows a
171
submit command, even when you only explain the steps or the user will run
172
the command themselves.
173
174
4. **Submit.** Pick the submit type:
175
176
* Native executable or shell script: see
177
[android_executable.md](references/android_executable.md).
178
* Instrumentation test APK: see
179
[instrumentation.md](references/instrumentation.md).
180
* Same binary with several configurations (different flags, inputs or
181
environment variables) per device: see
182
[multi_config_runs.md](references/multi_config_runs.md).
183
184
5. **Wait.** For runs longer than a few minutes, submit with `--async` and
185
follow [session_lifecycle.md](references/session_lifecycle.md).
186
187
6. **Collect results.** Download and map artifacts to devices with
188
[results.md](references/results.md).
189
190
7. **Report** one row per device: device ID, job folder (`job-NNN`), result,
191
key outputs, and the `gs://` path of the session folder. Call out failed,
192
timed-out or cancelled jobs explicitly instead of dropping them.
193
194
## Rules
195
196
* **Always set the timeout.** `--executable-timeout` (or
197
`--instrumentation-timeout`) defaults to `5m`; the valid range is `1m` to
198
`3h`. Estimate the run time and set it explicitly.
199
* **Arguments are comma-separated.** Each element of `--executable-args`
200
becomes one argument. Rewrite space-separated command lines. If a value
201
contains a comma, use the `^SEP^` prefix (see
202
[android_executable.md](references/android_executable.md)).
203
* **No shell in the direct call.** With a binary as `--executable` there is no
204
shell: set environment variables with `--executable-env-vars`, not `export`.
205
* **Do not overwrite shared inputs.** DDP fetches inputs when a job starts.
206
Never overwrite a `gs://` script or binary that a pending session uses; use
207
local paths (auto-uploaded) or a unique `gs://` path per run.
208
* **Label sessions** with `--labels` (for example `purpose=smoke,build=1234`)
209
so they are easy to find later.
210
* **Poll politely.** Never poll in a tight loop; poll every 30 to 60 seconds
211
and report progress (see
212
[session_lifecycle.md](references/session_lifecycle.md)).
213
* **Cancel on request.** If the user wants to stop, cancel the session (see
214
[session_lifecycle.md](references/session_lifecycle.md)) and tell the
215
user it was cancelled.
216
* **Do not use the Device Streaming API** (`devicestreaming.googleapis.com`,
217
`deviceSessions`) to run batch jobs; that is for interactive leases.
218
219
## Reference index
220
221
* [device_selection.md](references/device_selection.md): map device names
222
such as "Pixel 10" to catalog IDs, OS versions, physical vs virtual.
223
* [android_executable.md](references/android_executable.md): flags, direct
224
call, shared libraries, script as executable.
225
* [instrumentation.md](references/instrumentation.md): APK tests, sharding,
226
test targets.
227
* [session_lifecycle.md](references/session_lifecycle.md): sync vs async,
228
wait, describe, cancel, status and result types.
229
* [results.md](references/results.md): bucket layout, job-to-device mapping,
230
logs.
231
* [multi_config_runs.md](references/multi_config_runs.md): run
232
the same binary with several configurations per device.
233
* [troubleshooting.md](references/troubleshooting.md): common failures.
234