14

I am a budding android developer and if there is no easy way of configuring the adb server to run on another port then the inflexibility of the tools will force me to quit android app development.

A web search did not return any solutions.

I also searched for '5037' in all files in android sdk directory but did not find a setting there.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
jeets
  • 237
  • 1
  • 2
  • 4
  • This is annoying. I run into it when starting multiple eclipse instances (different workspaces). Since both have the android plugin, they conflict with each other and cause strange behavior - ex, one process shows up in one eclipse's ddms device view and one process (on same emulator) shows up in the other eclipse's ddms devices view. – Stan Kurdziel Oct 01 '10 at 06:20
  • 9
    You might want to reformulate your "question" to that it indeed contains a question. And take out the profanities ;-) We understand that you're frustrated, but don't complain to us, we didn't program adb. – pableu Oct 01 '10 at 07:35
  • 19
    `googled for 5 mins` Oh my god, 5 whole minutes?!?! – Falmarri Oct 01 '10 at 19:33
  • 3
    What is this.. `king quitting android app development` are you kind of joking out here.? – Veer Shrivastav May 20 '13 at 19:09
  • 4
    I can see why people reacted negatively to the original statement of the question, but **it's actually a quite important question, and has answers of ongoing value**. Tools with hardcoded assumptions are quite problematic when they collide with others making the same assumption, so it's good to know that there are ways to configure this. – Chris Stratton Oct 03 '14 at 16:32
  • If adb service runs at port 5037 then why does it locate devices in the range 5555 to 5585 ? Can anyone please explain me – Shivam Aggarwal Dec 03 '15 at 16:09

4 Answers4

47

Use the environment variable ANDROID_ADB_SERVER_PORT to select the port.

The following works under bash:

$ export ANDROID_ADB_SERVER_PORT=12345 
$ adb start-server
* daemon not running. starting it now on port 12345 *
* daemon started successfully *
$ adb devices
List of devices attached 
TA2070M5O6  device
$ ANDROID_ADB_SERVER_PORT=6789 adb devices
* daemon not running. starting it now on port 6789 *
* daemon started successfully *
List of devices attached 

In another terminal I ran:

$ ANDROID_ADB_SERVER_PORT=6789 emulator ...

Back to original terminal:

$ ANDROID_ADB_SERVER_PORT=6789 adb devices
List of devices attached 
emulator-5554   device
$ adb devices # ANDROID_ADB_SERVER_PORT was exported as 12345
List of devices attached 
TA2070M5O6  device

I found this via the Jenkins Android Emulator Plugin as I noticed it was running adb on a different port.

ashley willis
  • 1,601
  • 1
  • 13
  • 10
  • 6
    Is there a way to attach a specific device to a particular adb server ? – Jakub Czaplicki Mar 08 '13 at 14:36
  • you may have to run `sudo apt-get install android-tools-adb` from terminal before – tony gil Apr 20 '16 at 12:54
  • @tonygil Is there a way to do this? You just supplied the tools, how do you actually specify a device to a particular server? – ALM Dec 12 '18 at 01:42
  • @ALM my apologies for taking so long. I havent used ADB in a while, but this was a local wifi connection to debug my code (in Eclipse IDE on ubuntu box) on an android smartphone/tablet. – tony gil Feb 25 '19 at 11:37
  • @JakubCzaplicki yes - make sure to have `ANDROID_ADB_SERVER_PORT` set to the same port when running the emulator. For me this seems to work unless the adb server is started after the emulator is already running... – d4vidi Aug 14 '19 at 12:15
32

With the latest adb version,

Use option -P (Note: Caps P)to start adb server in a specific port.

For Example, Try

$adb -P 5038 start-server

It will list the devices attached to this specific adb server. If the adb server is not running then it will start a new adb server with the given port number.

Hope it helps someone reading this post.

Thanks.

balachandarkm
  • 855
  • 2
  • 9
  • 11
11

In Windows, go to Environment Variables – Add a new one called ANDROID_ADB_SERVER_PORT and set it to whatever you want, I've set to 5038.

Should look like this:

Solved it for me.

Benji
  • 946
  • 10
  • 12
2

There is another variable that supports this for connecting to a different machine's adb:

ADB_SERVER_SOCKET=tcp:some.other.host:1234 adb devices

To use it, you need to start adb on the other host with -a and probably background it too:

( adb -a -P 1234 nodaemon server & ) &
android.weasel
  • 3,343
  • 1
  • 30
  • 41