Changing default port (i.e. 5037) on which adb server runs

£可爱£侵袭症+ 提交于 2019-11-26 22:35:32

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.

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.

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.

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 & ) &
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!