Skip to content

Conversation

@andredestro
Copy link
Contributor

Summary

Fix emulator port selection by choosing an available even port instead of hardcoding 5554, and improve emulator detection heuristics so devices reported as hardware by adb are correctly recognized as emulators. Add unit tests covering detection and port selection/fallback.

What this does

  • Adds findAvailableEmulatorPort(devices) — scans the provided devices list and returns the first free even port in the range 5554–5584. Falls back to 5554 if none available.
  • Adds isLikelyEmulator(device) — heuristic detection using:
    • serial (e.g. emulator-5554)
    • type === 'emulator'
    • properties.device (starts with emu or contains generic)
    • properties.product (contains sdk_gphone or google_sdk)
    • model (contains android_sdk or sdk_gphone)
  • Updates selectDeviceByTarget to:
    • Use isLikelyEmulator(...) to build emulator list
    • Use the port returned by findAvailableEmulatorPort(...) when launching via runEmulator
  • Exports helpers for testing.
  • Adds Jest unit tests at run.spec.ts.

Why

  • Hardcoded 5554 caused failures when that port was already in use.
  • Some emulators are reported as type: 'hardware' by adb; improved heuristics prevent misclassification and make AVD selection more robust.

@andredestro andredestro force-pushed the fix/android/emulator-port-selection branch from a49d6c3 to 8100317 Compare December 15, 2025 10:04
Copy link

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - tested here with different combinations of emulators and physical devices, seems to be selecting the right emulator always. Nicely done!

@OS-pedrogustavobilro OS-pedrogustavobilro requested a review from a team December 15, 2025 15:43
@andredestro andredestro merged commit 45745fe into develop Dec 15, 2025
4 checks passed
@andredestro andredestro deleted the fix/android/emulator-port-selection branch December 15, 2025 16:04
github-actions bot pushed a commit that referenced this pull request Jan 7, 2026
## [2.0.2](v2.0.1...v2.0.2) (2026-01-07)

### Bug Fixes

* **android:** select available emulator port and improve emulator detection ([#399](#399)) ([45745fe](45745fe))
@Ionitron
Copy link
Collaborator

Ionitron commented Jan 7, 2026

🎉 This PR is included in version 2.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants