Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADB: missing port in specification

I've recently upgraded to Android SDK Platform-Tools version 28.0.2. Version information:

$ adb version Android Debug Bridge version 1.0.40 Version 28.0.2-5303910 

When using the adb connect command I now get the following error:

$ adb connect 192.168.1.20 missing port in specification: tcp:192.168.1.20 

ADB previously connected to devices using TCP port 5555 by default. I am still able to connect to my device by specifying this port number:

$ adb connect 192.168.1.20:5555 connected to 192.168.1.20:5555 

However, this is a minor inconvenience to me as I'm used to typing in just the IP address. Is there any way of telling this version of ADB to use TCP port 5555 by default?

like image 453
Michael Dodd Avatar asked Mar 14 '19 08:03

Michael Dodd


People also ask

What port does adb use?

When server starts, it always bind the local TCP port 5037. All ADB clients listen to 5037 TCP port to communicate with server request.

How do I change the default port for adb?

Use option -P (Note: Caps P)to start adb server in a specific port. 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.


1 Answers

Update

This bug has now been fixed as of ADB version 1.0.41, which is part of Platform Tools version 29.0.4. The fix for the bug was committed on 31st July 2019:

Restore default port for adb connect.

The default port of 5555 was removed a while back, but the help text was never updated, and other contexts still allow a default port.

Bug: https://issuetracker.google.com/128561172

Inputting adb connect 192.168.1.20 without the trailing port number now results in ADB connecting to the target device, restoring previous behaviour.

Old answer

This would appear to be a bug within ADB, introduced in December 2018 or January 2019. I believe this relates to recent changes to this else statement in socket_spec.cpp.

} else {     std::string addr(spec.substr(4));     port_value = -1;      // FIXME: ParseNetAddress rejects port 0. This currently doesn't hurt, because listening     //        on an address that isn't 'localhost' is unsupported.     if (!android::base::ParseNetAddress(addr, &hostname_value, &port_value, serial, error)) {         return false;     }      if (port_value == -1) {         *error = "missing port in specification: ";         *error += spec;         return false;     } } 

If a port value is not specified, the variable port_value is initialised at -1 and does not change. This value is not altered by android::base::ParseNetAddress either. If the ParseNetAddress check passes then we will always fall into the error-catching statement immediately afterwards.

like image 94
Michael Dodd Avatar answered Sep 19 '22 23:09

Michael Dodd