Skip to content

Commit 396081e

Browse files
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 description
1 parent b26aa65 commit 396081e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • packages/cli-platform-android/src/commands/runAndroid

packages/cli-platform-android/src/commands/runAndroid/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function runOnSpecificDevice(
236236
androidProject.appName,
237237
args.mode,
238238
args.tasks ?? buildTask,
239-
'install',
239+
'assemble',
240240
);
241241

242242
// using '-x lint' in order to ignore linting errors while building the apk

0 commit comments

Comments
 (0)