Commit 396081e
authored
fix(android): respect --device on run-android when multiple devices connected (#2796)
* fix(android): respect --device on run-android when multiple devices connected
When `react-native run-android --device <serial>` is invoked with more
than one device or emulator attached, Gradle's `installDebug` task
silently installs on a device of its own choosing instead of the one
named by `--device`. The flag is honored only for the post-Gradle
`adb install` step in `tryInstallAppOnDevice`, which is too late: the
APK has already been pushed to the wrong device, and on a fresh
emulator the second adb install can fail outright due to a
debug-keystore mismatch left behind by the Gradle install.
Root cause: `runOnSpecificDevice` builds the Gradle task list with the
`'install'` prefix (yielding `app:installDebug`) but neither sets
`ANDROID_SERIAL` on the gradle spawn nor passes
`-Pandroid.injected.serial=<device>`, so AGP picks a device by its
own logic. The interactive path already side-steps this by swapping
the build task to `assemble*` (line ~230), but the non-interactive
path keeps using `install*`.
This change mirrors that swap for the non-interactive path: Gradle
builds `app:assembleDebug` (or the corresponding flavored variant) and
`tryInstallAppOnDevice` then runs `adb -s <device> install -r -d <apk>`
as it always has, so the install lands on the device the user asked
for. No environment variables, no AGP-injected properties, and no
behavior change when only one device is connected.
`runOnAllDevices` is unchanged: it still uses `install*` because it
intentionally fans the install across every connected device.
* drop inline comment, explained in PR description1 parent b26aa65 commit 396081e
1 file changed
Lines changed: 1 addition & 1 deletion
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
0 commit comments