Skip to content

fix(platform-android): avoid probing physical devices as emulators#112

Open
kateinoigakukun wants to merge 1 commit intocallstackincubator:mainfrom
kateinoigakukun:fix/android-emulator-adb-id-filter
Open

fix(platform-android): avoid probing physical devices as emulators#112
kateinoigakukun wants to merge 1 commit intocallstackincubator:mainfrom
kateinoigakukun:fix/android-emulator-adb-id-filter

Conversation

@kateinoigakukun
Copy link
Copy Markdown

Description

When we specify an android emulator as the harness runner like below and connect a physical device, we get the following error.

const config = {
  runners: [
    androidPlatform({
      name: 'android',
      device: androidEmulator('Pixel_Tablet_Rootable'),
      bundleId: 'com.example',
    }),
  ]
};

export default config;
SubprocessError: Command failed with exit code 1: ~/Library/Android/sdk/platform-tools/adb -s <device-id> emu avd name
    at checkFailure (file:///path/to/node_modules/nano-spawn/source/result.js:40:9)
    at getResult (file:///path/to/node_modules/nano-spawn/source/result.js:17:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async Module.getEmulatorName (file:///path/to/node_modules/@react-native-harness/platform-android/dist/adb.js:195:24)
    at async getAdbId (file:///path/to/node_modules/@react-native-harness/platform-android/dist/adb-id.js:10:34)
    at async getAndroidEmulatorPlatformInstance (file:///path/to/node_modules/@react-native-harness/platform-android/dist/instance.js:108:17)
    at async Object.work (file:///path/to/node_modules/@react-native-harness/jest/dist/harness.js:217:36)
    at async withPlatformReadyTimeout (file:///path/to/node_modules/@react-native-harness/jest/dist/harness.js:36:16)
    at async Promise.all (index 1)
    at async file:///path/to/node_modules/@react-native-harness/jest/dist/harness.js:202:24

This is just because getAdbId tries to get an emulator name from a physical device.
This patch fixes Android emulator device resolution to skip non-emulator ADB IDs before querying AVD name. Also adds a focused regression test suite.

Testing

I manually tested with that previously problematic situation.

## Description
Fix Android emulator device resolution to skip non-emulator ADB IDs before querying AVD name, preventing harness runs from failing when both physical devices and emulators are connected. Also adds a focused regression test suite for mixed-device scenarios and introduces package-local Vite test config so nx test works for platform-android.

## Related Issue
No upstream issue link available in this branch context. The bug was reproduced from downstream integration usage where a connected physical device caused adb -s <serial> emu avd name to fail during emulator resolution.

## Context
getAdbId iterated all IDs from adb devices and called getEmulatorName for emulator-configured runs regardless of ID type. On physical devices this command is invalid and throws. The fix filters IDs to emulator-* before calling getEmulatorName, preserving existing matching behavior while avoiding false failures.

The regression tests intentionally use generic device serials and model names to avoid personal/local identifiers in upstream tests.

## Testing
- pnpm nx lint @react-native-harness/platform-android (pass)
- pnpm nx typecheck @react-native-harness/platform-android (pass)
- pnpm nx test @react-native-harness/platform-android -- --run src/__tests__/adb-id.test.ts (pass)
- Full target run currently has unrelated pre-existing failures in app-monitor.test.ts in this repo state
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

@kateinoigakukun is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant