How to start more than 16 Android emulators

Viewed 804

With 16 emulators running, adb devices shows

List of devices attached
emulator-5584
emulator-5582
emulator-5580
emulator-5578
emulator-5576
emulator-5574
emulator-5572
emulator-5570
emulator-5568
emulator-5566
emulator-5564
emulator-5562
emulator-5560
emulator-5558
emulator-5556
emulator-5554

To start the 17th emulator, I run:

emulator -avd Nexus_4_API_19_17 -ports 5586,5587

but I later get the following warning

emulator: WARNING: Requested adb port (5587) is outside the recommended range [5555,5586]. ADB may not function properly for the emulator. See -help-port for details.

And adb devices doesn't show new emulators. Running emulator -help-port doesn't provide any useful information:

At startup, the emulator tries to bind its control console at a free port starting from 5554, in increments of two (i.e. 5554, then 5556, 5558, etc..) this allows several emulator instances to run concurrently on the same machine, each one using a different console port number. use '-port ' to force an emulator instance to use a given console port note that must be an even integer between 5554 and 5584 included. +1 must also be free and will be reserved for ADB. if any of these ports is already used, the emulator will fail to start.

Is there a way to make adb work with more than 16 emulators ?

2 Answers

You need to increase ADB_LOCAL_TRANSPORT_MAX in adb/transport_local.cpp to the desired value and recompile the adb binary.

From v41, you can set ADB_LOCAL_TRANSPORT_MAX_PORT as an env-var without needing to recompile. This has the same effect as increasing transport_max count.

Run adb --help: my patch also added documentation for this environment variable at the bottom of the help text.

Related