ADB:规范中缺少端口

Mic*_*odd 30 android adb android-sdk-tools

我最近已升级到Android SDK平台工具版本28.0.2。版本信息:

$ adb version
Android Debug Bridge version 1.0.40
Version 28.0.2-5303910
Run Code Online (Sandbox Code Playgroud)

使用adb connect命令时,我现在得到以下错误:

$ adb connect 192.168.1.20
missing port in specification: tcp:192.168.1.20
Run Code Online (Sandbox Code Playgroud)

默认情况下,ADB以前使用TCP端口5555连接到设备。我仍然可以通过指定以下端口号连接到我的设备:

$ adb connect 192.168.1.20:5555
connected to 192.168.1.20:5555
Run Code Online (Sandbox Code Playgroud)

但是,这对我来说是一个小麻烦,因为我习惯于仅输入IP地址。有没有办法告诉此版本的ADB默认使用TCP端口5555?

Mic*_*odd 19

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

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.

  • @PonomarenkoOleh目前的解决方法是包括端口号,例如192.168.1.20:5555。但是,此错误是Google的责任,因此我们需要等待他们进行修复。 (6认同)

Sid*_*rth 10

我可以通过在后缀位置添加端口号来连接我的android手机。

例如,

$ adb杀服务器

$ ADB连接192.168.1.20:5555

它直接无法连接,这给了我上面的错误。

注意:端口号是强制性的,可能您的端口号当前不同,因此请找到该端口号,然后尝试重新连接。


小智 5

$ adb kill-server
$ adb connect 192.168.1.20
Run Code Online (Sandbox Code Playgroud)

只需杀死adb服务器并正常连接即可。重新启动服务器后,将恢复默认端口(5555)。