Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of devices connected to an ADB server

Tags:

android

adb

According to Android Debug Bridge :

The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example:

Emulator 1, console: 5554

Emulator 1, adb: 5555

Emulator 2, console: 5556

Emulator 2, adb: 5557 ...

The ADB server only checks for devices by scanning odd-numbered ports in the range 5555 to 5585 ( 30 ports in total) and assigns 2 ports for each device. Is ADB capable of accepting more than 15 Android Devices (15x2 ports) or can I connect more devices on the same computer? I think it is impossible to run more than one ADB servers on the same machine.

like image 372
glarkou Avatar asked Mar 29 '12 11:03

glarkou


2 Answers

You can run more than one instance of adb on the same computer using the environment variable ANDROID_ADB_SERVER_PORT. see more details on this answer.

With the -ports option on the emulator, you can specify any port, and then do:

$ adb connect localhost:PORT

If your phone is rooted you can restart adbd on another port (see another answer), and then:

$ adb connect IP_OF_DEVICE:PORT

The device is then available over wifi and does not need to be plugged in. Be aware that anyone on your wifi network can access your phone this way!

like image 197
ashley willis Avatar answered Sep 22 '22 07:09

ashley willis


Max number of ports used by adb can be changed by setting ADB_LOCAL_TRANSPORT_MAX_PORT environment variable. You can simply take a look on the adb code (it's opensource because it's part of Android). You can see that max number of adb ports is set like this:

static int adb_local_transport_max_port = DEFAULT_ADB_LOCAL_TRANSPORT_PORT + 16 * 2 - 1;

where DEFAULT_ADB_LOCAL_TRANSPORT_PORT is 5555. Each device requires 2 ports (console connection + adb connection). So use this formula to calculate your max port: max_port = 5555 + 2 * N + 1

Read here how to set environment variable on Windows. And for Linux/macOS it can be done by simply editing .bash_profile (or .profile) file in your home directory. So there's actually no need in additional adb servers like Ashley suggests in another answer.

like image 26
alexal1 Avatar answered Sep 24 '22 07:09

alexal1