如何使用 ADB over TCP 连接到 Android?

发布于 2024-08-28 01:29:21 字数 478 浏览 10 评论 0 原文

我正在尝试在 Motorola Droid 上调试应用程序,但连接到通过 USB 设备。我的开发服务器是在 Hyper-V 中运行的 Windows 7 64 位虚拟机,等等我无法通过访客或主机中的 USB 直接连接。

我安装了几个不同的 USB-over-TCP 解决方案,但自 ADB Monitor反复报“devicemonitor无法启动监控”。有没有办法使用网络而不是 USB 连接或其他可行的选项直接从开发计算机上的客户端连接到设备上的守护程序?

I am attempting to debug an application on a Motorola Droid, but I am having some difficulty connecting to the device via USB. My development server is a Windows 7 64-bit VM running in Hyper-V, and so I cannot connect directly via USB in the guest or from the host.

I installed a couple of different USB-over-TCP solutions, but the connection appears to have issues since the ADB monitor reports "devicemonitor failed to start monitoring" repeatedly. Is there a way to connect directly from the client on the development machine to the daemon on the device using the network instead of the USB connection or possibly another viable options?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

丶视觉 2024-09-04 01:29:21

手动过程

从您的设备(如果已 root)

根据 a post xda-developers,您可以使用以下命令从设备通过 Wi-Fi 启用 ADB:

su
setprop service.adb.tcp.port 5555
stop adbd
start adbd

如果您已经具有 USB访问权限

setprop service.adb.tcp.port -1
stop adbd
start adbd

(无需 root )

如果您已有 USB,则切换到使用 Wi-Fi 会更容易。从通过 USB 连接设备的计算机上的命令行中,发出命令请

adb tcpip 5555
adb connect 192.168.0.101:5555

务必将 192.168.0.101 替换为实际分配给您的设备的 IP 地址。完成后,您可以通过运行以下命令断开与 adb tcp 会话的连接:

adb disconnect 192.168.0.101:5555

您可以通过两种方式查找平板电脑的 IP 地址:

手动 IP 发现:

进入 Android 的 WiFi 设置,单击菜单按钮在操作栏中(垂直省略号),点击高级并在屏幕底部看到 IP 地址。

使用 ADB 发现 IP:

通过 adb 执行以下命令:

adb shell ip -f inet addr show wlan0

告诉 ADB 守护程序返回到通过 USB 进行监听的

adb usb

应用程序来自动执行该过程

Google Play 上还有多个应用程序可以自动执行此过程。快速搜索后建议使用 adbWireless,< a href="https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en" rel="noreferrer">WiFi ADB 和 ADB WiFi。所有这些都需要 root 访问权限,但 adbWireless 需要的权限较少。

Manual Process

From your device, if it is rooted

According to a post on xda-developers, you can enable ADB over Wi-Fi from the device with the commands:

su
setprop service.adb.tcp.port 5555
stop adbd
start adbd

And you can disable it and return ADB to listening on USB with

setprop service.adb.tcp.port -1
stop adbd
start adbd

From a computer, if you have USB access already (no root required)

It is even easier to switch to using Wi-Fi, if you already have USB. From a command line on the computer that has the device connected via USB, issue the commands

adb tcpip 5555
adb connect 192.168.0.101:5555

Be sure to replace 192.168.0.101 with the IP address that is actually assigned to your device. Once you are done, you can disconnect from the adb tcp session by running:

adb disconnect 192.168.0.101:5555

You can find the IP address of a tablet in two ways:

Manual IP Discovery:

Go into Android's WiFi settings, click the menu button in the action bar (the vertical ellipsis), hit Advanced and see the IP address at the bottom of the screen.

Use ADB to discover IP:

Execute the following command via adb:

adb shell ip -f inet addr show wlan0

To tell the ADB daemon return to listening over USB

adb usb

Apps to automate the process

There are also several apps on Google Play that automate this process. A quick search suggests adbWireless, WiFi ADB and ADB WiFi. All of these require root access, but adbWireless requires fewer permissions.

沒落の蓅哖 2024-09-04 01:29:21

如果您的手机已root,这非常简单。

Google Play 下载终端模拟器(有很多是免费的)。确保您的 Android 设备已连接到 Wi-Fi 并获取 Wi-Fi IP 地址。打开终端程序并输入:

su
setprop service.adb.tcp.port 5555
stop adbd
start adbd

现在转到您的计算机(假设您使用的是 Windows)并在桌面上创建“cmd.exe”的快捷方式(不带引号)。

右键单击 cmd 快捷方式并选择“以管理员身份运行”

更改为 android-sdk-windows\tools 文件夹

类型:

adb connect ***wifi.ip.address***:5555

(example: adb connect 192.168.0.105:5555)

adb 现在应该说你已连接。

注意:如果您太快发出连接命令,则可能会失败。因此,在您说这不起作用之前,请至少尝试两次,每次间隔五秒。

This is really simple if your phone is rooted.

Download a terminal emulator from Google Play (there are lots that are free). Make sure that your Android device is connected to your Wi-Fi and get the Wi-Fi IP address. Open the terminal program and type:

su
setprop service.adb.tcp.port 5555
stop adbd
start adbd

Now go to your computer (assuming that you are using Windows) and create a shortcut on the desktop for "cmd.exe" (without the quotations).

Right click on the cmd shortcut and choose "Run as Administrator"

Change to your android-sdk-windows\tools folder

Type:

adb connect ***wifi.ip.address***:5555

(example: adb connect 192.168.0.105:5555)

adb should now say that you are connected.

Note: if you are too fast to give the connect command it may fail. So try at least two times five seconds apart before you say this doesn't work.

一向肩并 2024-09-04 01:29:21
  1. 通过 USB 连接设备并确保调试正常,然后运行:

    <前><代码>adb tcpip 5555
    adb connect :5555

  2. 断开 USB 并继续进行无线调试。

  3. 完成后想要切换回 USB 调试,请运行:

    adb -s :5555
    

要查找设备的 IP 地址,请转至 Settings >无线网络>高级>您设备上的 IP 地址 或运行 adb shell netcfg

无需root。一次只能调试一台设备。

请参阅此 XDA 帖子

adb 命令位于 Android SDK 的 platform-tools 文件夹中。

  1. Connect device via USB and make sure debugging is working, then run:

    adb tcpip 5555
    adb connect <DEVICE_IP_ADDRESS>:5555
    
  2. Disconnect USB and proceed with wireless debugging.

  3. When you're done and want to switch back to USB debugging, run:

    adb -s <DEVICE_IP_ADDRESS>:5555
    

To find the IP address of your device, go to Settings > Wi-Fi > Advanced > IP Address on your device or run adb shell netcfg.

No root required. Only one device can be debugged at a time.

See this XDA post.

The adb command is located in the platform-tools folder of the Android SDK.

蒲公英的约定 2024-09-04 01:29:21

假设您将 adb 路径保存到 Windows 环境路径中

  1. 在 Android 中激活调试模式

  2. 通过 USB 连接到 PC

  3. 打开命令提示符类型:adb tcpip 5555

  4. 断开平板电脑或智能手机与电脑的连接

  5. 打开命令提示符类型:adb connect IPADDRESS(IPADDRESS 是平板电脑或智能手机的 DHCP/IP 地址,您可以通过 Wi-Fi -> 当前连接的网络找到该地址)< /p>

现在在命令中提示您应该看到如下结果:connected to xxx.xxx.xxx.xxx:5555

Assume you saved adb path into your Windows environment path

  1. Activate debug mode in Android

  2. Connect to PC via USB

  3. Open command prompt type: adb tcpip 5555

  4. Disconnect your tablet or smartphone from pc

  5. Open command prompt type: adb connect IPADDRESS (IPADDRESS is the DHCP/IP address of your tablet or smartphone, which you can find by Wi-Fi -> current connected network)

Now in command prompt you should see the result like: connected to xxx.xxx.xxx.xxx:5555

雪落纷纷 2024-09-04 01:29:21

来自adb --help

connect <host>:<port>         - Connect to a device via TCP/IP

顺便说一句,这是一个命令行选项。

您应该尝试将手机连接到 Wi-Fi,然后从路由器获取其 IP 地址。它不适用于蜂窝网络。

端口是5554。

From adb --help:

connect <host>:<port>         - Connect to a device via TCP/IP

That's a command-line option by the way.

You should try connecting the phone to your Wi-Fi, and then get its IP address from your router. It's not going to work on the cell network.

The port is 5554.

浅忆流年 2024-09-04 01:29:21

对于 Windows 用户:

第 1 步:
您必须在 Android 手机中启用开发者选项。
您可以使用这种方式启用开发者选项。
• 打开设置>关于>软件信息>更多。
• 然后点击“版本号”七次以启用开发人员选项。
• 返回“设置”菜单,现在您将能够在那里看到“开发人员选项”。
• 点击它并从下一个屏幕上的菜单中打开“USB 调试”。

第 2 步:

打开 cmd 并输入 adb。
如果您发现 adb 不是有效命令,那么您必须添加环境变量的路径。

•首先进入您的 SDK 安装文件夹
遵循此路径,此路径仅作为示例。
D:\softwares\Development\Andoird\SDK\sdk\platform-tools\;
D:\softwares\Development\Andoird\SDK\sdk\tools;
• 现在搜索Windows系统高级设置


输入图片此处描述

打开环境变量。

输入图片此处描述

然后打开路径并粘贴以下路径
这是一个例子。
您的SDK路径与我的不同,请使用您的。 D:\softwares\Development\Andoird\SDK\sdk\platform-tools\;
D:\softwares\Development\Andoird\SDK\sdk\tools;

在此处输入图像描述

第 3 步:

打开 cmd 并输入 adb。如果您仍然看到 adb 不是有效命令,则说明您的路径尚未正确设置,请按照上述步骤操作。

输入图片这里的描述

现在您可以将您的Android手机连接到PC。

打开cmd并输入adb devices,您就可以看到您的设备。
查找您的手机 IP 地址。

在此处输入图像描述

类型:- adb tcpip 5555

在此处输入图像描述

获取手机的 IP 地址

adb shell netcfg

adb connect "IP address of your phone"

现在运行您的android 项目,如果没有看到您的设备,请再次输入 adb connect 您手机的 IP 地址

在此处输入图像描述

在此处输入图像描述

对于 Linux 和 macOS 用户

第 1 步:打开终端并使用

sudo apt-get install android-tools-adb android-tools-fastboot

安装 adb通过 USB 线将手机连接到 PC。
在终端中输入以下命令

adb tcpip 5555

使用adb,连接您的Android手机IP地址。

取出手机。

For Windows users:

Step 1:
You have to enable Developer options in your Android phone.
You can enable Developer options using this way.
• Open Settings> About> Software Information> More.
• Then tap “Build number” seven times to enable Developer options.
• Go back to Settings menu and now you'll be able to see “Developer options” there.
• Tap it and turn on USB Debugging from the menu on the next screen.

Step 2:

Open cmd and type adb.
if you find that adb is not valid command then you have to add a path to the environment variable.

•First go to you SDK installed folder
Follow this path and this path is just for an example.
D:\softwares\Development\Andoird\SDK\sdk\platform-tools\;
D:\softwares\Development\Andoird\SDK\sdk\tools;
• Now search on windows system advanced setting


enter image description here

Open the Environment variable.

enter image description here

then open path and paste the following path
this is an example.
You SDK path is different from mine please use yours. D:\softwares\Development\Andoird\SDK\sdk\platform-tools\;
D:\softwares\Development\Andoird\SDK\sdk\tools;

enter image description here

Step 3:

Open cmd and type adb. if you still see that adb is not valid command then your path has not set properly follow above steps.

enter image description here

Now you can connect your android phone to PC.

Open cmd and type adb devices and you can see your device.
Find you phone ip address.

enter image description here

Type:- adb tcpip 5555

enter image description here

Get the IP address of your phone

adb shell netcfg

Now,

adb connect "IP address of your phone"

Now run your android project and if not see you device then type again adb connect IP address of your phone

enter image description here

enter image description here

For Linux and macOS users:

Step 1: open terminal and install adb using

sudo apt-get install android-tools-adb android-tools-fastboot

Connect your phone via USB cable to PC.
Type following command in terminal

adb tcpip 5555

Using adb, connect your android phone ip address.

Remove your phone.

安稳善良 2024-09-04 01:29:21

从非 root 设备上的计算机

(请注意,这也可以使用 root 设备来完成,但您可以在不需要 USB 连接的 root 设备上使用 shell)

首先,打开命令提示符 (CMD) 。如果您使用 Android Studio 或 IntelliJ,您可以使用其中包含的控制台。

如果路径中添加了adb,则可以跳过cd部分。


如果可能,打开 SDK 位置,右键单击,然后按“在此处启动命令提示符”。并非所有系统都有此选项,因此您还必须执行此(/这些)命令:

Windows:更改驱动器(如果适用)

D: 

并访问 sdk 和平台工具。将此路径替换为您的 SDK 位置:

cd /sdk/path/here/platform-tools

现在您可以访问 Android 调试桥。


将设备连接到计算机后,执行以下操作:

adb tcpip <port> 
adb connect <ip>:<port>

其中 是您要连接的端口(默认为 5555), 是您要连接的端口(默认为 5555)。 是您要连接的设备的IP。

请注意:5555 是默认端口,只需写入 IP 地址即可连接。如果您使用自定义端口,至少可以提高一点安全性。通过 Wi-Fi 进行 USB 调试可能会被滥用,但前提是该设备连接到想要滥用该设备的计算机。使用非默认端口至少会使连接变得更加困难。

如果您使用自定义端口,请确保将其添加在 IP 之后。不写入端口会连接到 5555,如果您不使用该端口,连接将会失败。

您可以通过两种方式查找设备的 IP 地址:

  • 具体名称可能会有所不同,具体取决于您的设备。打开设置并转到关于设备 -> 状态 -> IP 地址

  • 使用 ADB 获取 IP

从控制台,执行以下操作:

adb shell ip -f inet addr show wlan0

一旦完成连接,您就可以断开设备与您的设备的连接。电脑通过这样做:

adb disconnect <ip>:<port>

或者没有IP来断开所有设备。如果您使用自定义端口,则必须指定要断开连接的端口。这里的默认值也是 5555。

要禁用端口(如果这是您想要执行的操作),请在连接的设备上执行以下命令:

adb usb

或者您可以重新启动设备以删除 tcpip 连接

从 root 设备上的计算机

首先,您需要访问 shell。您可以使用 USB 电缆连接设备并使用 adb shell,或者从 Google Play、FDroid 或其他来源下载应用程序。

然后您可以:

su
setprop service.adb.tcp.port <port>
stop adbd
start adbd

要连接设备,您可以像非 root 版本一样通过执行 adb connect : 来连接设备。

如果您想禁用端口并返回 USB 监听:

setprop service.adb.tcp.port -1
stop adbd
start adbd

您还可以使用 Android Studio 插件来为您完成此操作(现在不记得名称了),对于 root 用户,还可以选择下载用于设置手机连接的 Android 应用程序(可能仍需要 adb connect)。

有些手机在开发者选项中有一项设置(这适用于一些未 root 的手机,但也可能是一些已 root 的手机),允许在没有 root 或计算机连接的情况下从设备本身通过 Wi-Fi 切换 ADB开始吧。虽然很少有手机有这个功能

From a computer on a non-rooted device

(Note that this can be done using a rooted device as well, but you can use a shell on a rooted device which doesn't require a USB connection)

Firstly, open command prompt (CMD). If you use Android Studio or IntelliJ there is a console included in there you can use.

If you have adb added to the path, you can skip the cd part.


If possible, open the SDK location, right click, and press "start command prompt here". Not all have this option so you have to do this (/these) commands as well:

Windows: change the drive (if applicable)

D: 

And access the sdk and platform tools. Replace this path with your SDK location:

cd /sdk/path/here/platform-tools

Now you have access to the Android debug bridge.


With the device connected to the computer, do:

adb tcpip <port> 
adb connect <ip>:<port>

Where <port> is the port you want to connect to (default is 5555) and <ip> is the IP of the device you want to connect to.

Please note: 5555 is the default port and just writing the IP address connects it. If you use a custom port you can at least improve the security a bit. USB debugging over Wi-Fi can be abused, but only if the device is connected to the computer who wants to abuse the device. Using a non-default port at least makes it a bit harder to connect.

If you use a custom port, make sure to add it after the IP. Writing no port connects to 5555 and if you didn't use that the connection will fail.

You can find the IP address of a device in two ways:

  • Depending on your device, the exact names may vary. Open settings and go to About device -> Status -> IP address

  • Use ADB to get the IP

From the console, do:

adb shell ip -f inet addr show wlan0

And once you are finished with the connection, you can disconnect the device from your computer by doing:

adb disconnect <ip>:<port>

Or no IP to disconnect all devices. If you used a custom port, you must specify which port to disconnect from. The default is 5555 here as well.

To disable the port (if that is something you want to do) you do this command with the device connected:

adb usb

Or you can restart the device to remove the tcpip connection

From a computer on a rooted device

Firstly, you need access to the shell. You either connect the device using a usb cable and use adb shell or download an app from Google Play, FDroid, or some other source.

Then you do:

su
setprop service.adb.tcp.port <port>
stop adbd
start adbd

And to connect the device, you do as in the non-rooted version by doing adb connect <ip>:<port>.

And if you want to disable the port and go back to USB listening:

setprop service.adb.tcp.port -1
stop adbd
start adbd

You can also use an Android Studio plugin to do it for you (don't remember the name right now), and for rooted users there's also the option of downloading an Android app to set up the phone connection (adb connect is probably still required).

Some phones have a setting in developer options (this applies to some unrooted phones, though probably some rooted phones too) that allows for toggling ADB over Wi-Fi from the device itself without root or a computer connection to start it. Though there are few phones that have that

迷爱 2024-09-04 01:29:21

我需要让 USB 和 TCPIP 都能为 ADB 工作(不要问),所以 执行了以下操作(使用其他人从 xda-developers 发布的说明) :

我使用 adb shell

su
#Set the port number for adbd
setprop service.adb.tcp.port 5555

#Run the adbd daemon *again* instead of doing stop/start, so there
#are two instances of adbd running.
adbd &

#Set the port back to USB, so the next time ADB is started it's
#on USB again.
setprop service.adb.tcp.port -1

exit

I needed to get both USB and TCPIP working for ADB (don't ask), so I did the following (using directions others have posted from xda-developers)

Using adb shell:

su
#Set the port number for adbd
setprop service.adb.tcp.port 5555

#Run the adbd daemon *again* instead of doing stop/start, so there
#are two instances of adbd running.
adbd &

#Set the port back to USB, so the next time ADB is started it's
#on USB again.
setprop service.adb.tcp.port -1

exit
夜深人未静 2024-09-04 01:29:21

使用 TCP 端口连接平板电脑。
确保您的系统和设备连接到同一网络。

  1. 打开控制台cmd.exe
  2. 输入adb tcpip 5555
  3. 转到系统->开发选项-> USB调试 -->取消选中 TCPIP 连接
  4. 类型 adb connect 192.168.1.2 这是您的设备 IP 地址
  5. 连接到 192.168.1.2

使用端口转发连接
尝试进行端口转发,

adb forward tcp: tcp:

如下:

adb 转发 tcp:5555 tcp:5555。

C:\Users\abc>adb 转发 tcp:7612 tcp:7612

C:\Users\abc>adb tcpip 7612 以 TCP 模式重新启动端口:7612

C:\Users\abc>adb connect 10.0.0.1:7612

连接到10.0.0.1:7612

如果您收到消息错误:找不到设备,请将 USB 设备连接到系统,然后按照相同的步骤操作。
对于已取得 root 权限的设备

setprop service.adb.tcp.port 5555
stop adbd
start adbd

To connect your tablet using TCP port.
Make sure your system and device is connected to same network.

  1. Open console cmd.exe
  2. Type adb tcpip 5555
  3. Go to System -> Development option -> USB debugging --> Uncheck it for TCPIP connection
  4. Type adb connect 192.168.1.2 this is your device IP address
  5. Connected to 192.168.1.2

Connected using port forward
Try to do port forwarding,

adb forward tcp:<PC port> tcp:<device port>

like:

adb forward tcp:5555 tcp:5555.

C:\Users\abc>adb forward tcp:7612 tcp:7612

C:\Users\abc>adb tcpip 7612 restarting in TCP mode port: 7612

C:\Users\abc>adb connect 10.0.0.1:7612

connected to 10.0.0.1:7612

If you get message error: device not found connect a usb device to system then follow same procedure.
for a rooted device

setprop service.adb.tcp.port 5555
stop adbd
start adbd
岛徒 2024-09-04 01:29:21

我不知道如何在没有任何 USB 连接的情况下连接设备,但如果您设法在另一台计算机上连接它,您可以通过从

adb tcpip <port>

终端发出命令将 adbd 切换到 TCP 模式,并从任何 PC 通过 wifi 连接到您的设备在网络上:

adb connect <ip>:<port>

也许还可以从设备上的终端切换到 TCP 模式。

I do not know how to connect the device without any USB connection at all, but if you manage to connect it maybe at another computer you can switch the adbd to TCP mode by issuing

adb tcpip <port>

from a terminal and connect to your device over wifi from any PC on the network by:

adb connect <ip>:<port>

Maybe it is also possible to switch to TCP mode from a terminal on the device.

做个ˇ局外人 2024-09-04 01:29:21

首先,您必须通过 USB 连接您的设备,

然后将您的设备连接到 WIFI 并获取 IP 地址。
当仍然通过 USB 连接时,在命令行中或通过 Android Studio 终端键入此内容,

adb tcpip 5555
adb connect <device IP>:5555

您将看到这些消息:

restarting in TCP mode port: 5555
connected to 172.11.0.16:5555

现在移除 USB 电缆,您仍然会看到 logcat 正常

完成。享受

First you must connect your device via USB

Then connect your device to WIFI and get the IP address.
While still connect via usb type this in command line or via Android Studio Terminal

adb tcpip 5555
adb connect <device IP>:5555

You will see these messages:

restarting in TCP mode port: 5555
connected to 172.11.0.16:5555

Now remove the USB cable and you will still see your logcat as normal

Done. Enjoy

绿光 2024-09-04 01:29:21

如果您想轻松连接设备以通过 WiFi 运行、调试或部署 Android 应用程序,您可以使用我开发的开源 IntelliJ 插件。 这里是代码,这里插件可供使用。

使用方法非常简单。这里有一个 gif:

在此处输入图像描述

If you want to easily connect your device to run, debug or deploy your Android apps over WiFi you can use an open source IntelliJ Plugin I've developed. Here is the code and here the plugin ready to be used.

The usage is quite simple. Here you have a gif:

enter image description here

望她远 2024-09-04 01:29:21

正如布莱恩所说:

根据 xda-developers 上的帖子,您可以使用以下命令从设备通过 WiFi 启用 ADB

setprop service.adb.tcp.port 5555

停止adbd

启动adbd

您可以禁用它并使 ADB 返回到侦听 USB

setprop service.adb.tcp.port -1

停止adbd

启动adbd

如果您已有 USB 访问权限,则切换到使用 WiFi 会更容易。从通过 USB 连接设备的计算机上的命令行中,发出命令

亚行 TCPIP 5555

亚行连接192.168.0.101:5555

告诉 ADB 守护进程返回通过 USB 监听

adb USB

Android Market 上还有多个应用程序可以自动执行此过程。

它有效。您只需要访问 android shell 并输入这些命令...

市场上还有另一种(更简单的)解决方案:adbWireless,它会自动设置您的手机。

需要root!对于两个...

As Brian said:

According to a post on xda-developers, you can enable ADB over WiFi from the device with the commands

setprop service.adb.tcp.port 5555

stop adbd

start adbd

And you can disable it and return ADB to listening on USB with

setprop service.adb.tcp.port -1

stop adbd

start adbd

If you have USB access already, it is even easier to switch to using WiFi. From a command line on the computer that has the device connected via USB, issue the commands

adb tcpip 5555

adb connect 192.168.0.101:5555

To tell the ADB daemon return to listening over USB

adb usb

There are also several apps on the Android Market that automate this process.

It works.You just need to access the android shell and type those commands...

One other (easier) solution is on the Market: adbWireless, it will automatically set your phone.

Root is required! for both...

弥繁 2024-09-04 01:29:21
adb tcpip 5555

很奇怪,但这仅适用于我连接了 USB 电缆的情况,然后我可以拔下 USB 并与其他所有 adb 一起使用。

返回 USB 时也是如此,

adb usb

仅当 USB 连接时才有效。

并不重要

setprop service.adb.tcp.port 5555

我是否发出or

setprop service.adb.tcp.port -1

then stop & 。启动 adbd,我仍然需要 USB 电缆,否则它不起作用。

因此,如果我的 ADB over USB 无法工作,我打赌我也无法启用 ADB over WiFi。

adb tcpip 5555

Weird, but this only works for me if I have the USB cable connected, then I can unplug the usb and go for it with everything else adb.

and the same when returning to usb,

adb usb

will only work if usb is connected.

It doesn't matter if I issue the

setprop service.adb.tcp.port 5555

or

setprop service.adb.tcp.port -1

then stop & start adbd, I still need the usb cable in or it doesn't work.

So, if my ADB over usb wasn't working, I bet I wouldn't be able to enable ADB over WiFi either.

北方。的韩爷 2024-09-04 01:29:21

要仅使用一个命令在 TCP 和 USB 模式之间切换,您可以将其添加到 /init.rc

on property:service.adb.tcp.port=*
    restart adbd

on property:service.adb.tcp.enable=1
    setprop service.adb.tcp.port 5555

on property:service.adb.tcp.enable=0
    setprop service.adb.tcp.port -1

现在您可以使用属性 service.adb.tcp.enable 来启用或禁用端口 5555 上的侦听。运行 netstat 检查其是否正在侦听。正如您所看到的,如果您确实希望手动更改 service.adb.tcp.port,它也会触发。

To switch between TCP and USB modes with just one command, you can add this to /init.rc:

on property:service.adb.tcp.port=*
    restart adbd

on property:service.adb.tcp.enable=1
    setprop service.adb.tcp.port 5555

on property:service.adb.tcp.enable=0
    setprop service.adb.tcp.port -1

And now you can use property service.adb.tcp.enable to enable or disable listening on port 5555. Run netstat to check whether it's listening. As you can see it will also trigger if you do wish to change service.adb.tcp.port manually.

呢古 2024-09-04 01:29:21

Bash 实用函数:

function adb-connect-to-wifi {
    ip="$(adb shell ip route | awk '{print $9}')"
    port=5555
    adb tcpip ${port}
    adb connect ${ip}:${port}
}

Bash util function:

function adb-connect-to-wifi {
    ip="$(adb shell ip route | awk '{print $9}')"
    port=5555
    adb tcpip ${port}
    adb connect ${ip}:${port}
}
故笙诉离歌 2024-09-04 01:29:21

步骤 1.

确保您的 adb 主机和 Android 设备两者位于同一 Wifi 网络上。

步骤 2.

使用 USB 数据线将 Android 设备与计算机连接。一旦执行此操作,您的主机将检测您的设备,并且 adb 将开始在计算机上以 USB 模式运行。您可以使用adb devices检查连接的设备,同时通过执行adb usb确保adb正在USB模式下运行。

$ adb usb
restarting in USB mode
$ adb devices
List of devices attached
ZX1D63HX9R  device

步骤 3.

使用以下命令以 tcpip 模式重新启动 adb:

$ adb tcpip 5556
restarting in TCP mode port: 5556

步骤 4.

找出 Android 设备的 IP 地址。有几种方法可以做到这一点:

  • 方式:1转到“设置”->“关于手机/平板电脑->状态-> IP 地址。
  • 方式:2 转至可用 Wi-Fi 网络列表。您所连接的那个,点击它并了解您的 IP。
  • 方式:3尝试$ adb shell netcfg

现在您知道了设备的 IP 地址,请将 adb 主机连接到它。

$ adb connect 192.168.0.102:5556
already connected to 192.168.0.102:5556
$ adb devices
List of devices attached
ZX1D63HX9R  device
192.168.0.102:5556  device

步骤 5.

拔下 USB 电缆,您应该已连接到您的设备。如果您在 adb devices 中没有看到它,则只需使用上一步的命令重新连接:

$ adb connect 192.168.0.102:5556
connected to 192.168.0.102:5556
$ adb devices
List of devices attached
192.168.0.102:5556  device

要么您现在就可以开始,要么您需要通过执行 adb 来终止您的 adb 服务器Kill-server 并再次执行所有步骤。

希望有帮助!

参考:

STEP 1.

Make sure both your adb host computer and Android device are on the same Wifi network.

STEP 2.

Connect the Android device with the computer using your USB cable. As soon as you do that, your host computer will detect your device and adb will start running in the USB mode on the computer. You can check the attached devices with adb devices whereas ensure that adb is running in the USB mode by executing adb usb.

$ adb usb
restarting in USB mode
$ adb devices
List of devices attached
ZX1D63HX9R  device

STEP 3.

Restart adb in tcpip mode with this command:

$ adb tcpip 5556
restarting in TCP mode port: 5556

STEP 4.

Find out the IP address of the Android device. There are several ways to do that:

  • WAY: 1 Go to Settings -> About phone/tablet -> Status -> IP address.
  • WAY: 2 Go to the list of Wi-fi networks available. The one to which you’re connected, tap on that and get to know your IP.
  • WAY: 3 Try $ adb shell netcfg.

Now that you know the IP address of your device, connect your adb host to it.

$ adb connect 192.168.0.102:5556
already connected to 192.168.0.102:5556
$ adb devices
List of devices attached
ZX1D63HX9R  device
192.168.0.102:5556  device

STEP 5.

Remove the USB cable and you should be connected to your device. If you don’t see it in adb devices then just reconnect using the previous step’s command:

$ adb connect 192.168.0.102:5556
connected to 192.168.0.102:5556
$ adb devices
List of devices attached
192.168.0.102:5556  device

Either you’re good to go now or you’ll need to kill your adb server by executing adb kill-server and go through all the steps again once more.

Hope that helps!

Reference:

时间你老了 2024-09-04 01:29:21

这些是我遵循的步骤,它对我有用,

  1. adb shell ifconfig(从这里获取设备的IP地址)

  2. adb tcpip 7777(将adb连接到某个端口)

  3. adb connect "ipaddress":7777

These are the steps I followed and it worked for me,

  1. adb shell ifconfig (get the ip address of the device from here)

  2. adb tcpip 7777 (connect adb to some port)

  3. adb connect "ipaddress":7777

一桥轻雨一伞开 2024-09-04 01:29:21

您还可以使用 SSH 本地端口转发。但它仍然涉及 USB 电缆。使用 USB 将手机连接到运行 sshd 的计算机(主机)。在远程(来宾)电脑上启动具有端口转发/隧道功能的 SSH 客户端。示例:

plink -L 5037:localhost:5037 <host_IP_address>

我使用此结构将我的设备连接到虚拟机。 Eltima USB 转以太网不够稳定(调试期间超时)。

SSH 隧道免费且更可靠。

You can also use SSH local port forwarding. But it still involves a USB cable. Connect your phone using USB to a computer (host) with an sshd running. On a remote (guest) pc start an SSH client capable of portforwarding/tunneling. Example:

plink -L 5037:localhost:5037 <host_IP_address>

I use this construction to connect my device to a virtual machine. Eltima USB to Ethernet wasn't stable enough (timeouts during debug).

SSH tunneling works for free and is more reliable.

哭泣的笑容 2024-09-04 01:29:21

我发现其他答案令人困惑。使用 adbWireless 更简单:

http://ppareit.github.com/AdbConnect/

只需安装一个应用程序在您的手机上通过 wifi 切换调试,安装 eclipse 插件即可完成。

I find the other answers confusing. Far simpler to use adbWireless:

http://ppareit.github.com/AdbConnect/

Simply install an app on your phone to toggle debugging over wifi, install an eclipse plug-in and you're done.

拥抱影子 2024-09-04 01:29:21

我整理了一个批处理文件,用于通过 TCP 自动启用 ADB 并将其连接到通过 USB 连接的设备。有了它,您不必手动输入 IP。

@echo off
setlocal

REM Use a default env variable to find adb if possible
if NOT "%AndroidSDK%" == "" set PATH=%PATH%;%AndroidSDK%\platform-tools

REM If off is first parameter then we turn off the tcp connection.
if "%1%" == "off" goto off

REM Set vars
set port=%1
set int=%2
if "%port%" == "" set port=5557
if "%int%" == "" set int=wlan0

REM Enable TCP
adb -d wait-for-device tcpip %port%

REM Get IP Address from device
set shellCmd="ip addr show %int% | grep 'inet [0-9]{1,3}(\.[0-9]{1,3}){3}' -oE | grep '[0-9]{1,3}(\.[0-9]{1,3}){3}' -oE"
for /f %%i in ('adb wait-for-device shell %shellCmd%') do set IP=%%i

REM Connect ADB to device
adb connect %IP%:%port%

goto end

:fail
echo adbWifi [port] [interface]
echo adbWifi off
goto end

:off
adb wait-for-device usb

:end

I put together a batch file for automatic enabling and connecting ADB via TCP, to a device connected via USB. With it you don't have to put in the IP manually.

@echo off
setlocal

REM Use a default env variable to find adb if possible
if NOT "%AndroidSDK%" == "" set PATH=%PATH%;%AndroidSDK%\platform-tools

REM If off is first parameter then we turn off the tcp connection.
if "%1%" == "off" goto off

REM Set vars
set port=%1
set int=%2
if "%port%" == "" set port=5557
if "%int%" == "" set int=wlan0

REM Enable TCP
adb -d wait-for-device tcpip %port%

REM Get IP Address from device
set shellCmd="ip addr show %int% | grep 'inet [0-9]{1,3}(\.[0-9]{1,3}){3}' -oE | grep '[0-9]{1,3}(\.[0-9]{1,3}){3}' -oE"
for /f %%i in ('adb wait-for-device shell %shellCmd%') do set IP=%%i

REM Connect ADB to device
adb connect %IP%:%port%

goto end

:fail
echo adbWifi [port] [interface]
echo adbWifi off
goto end

:off
adb wait-for-device usb

:end
对风讲故事 2024-09-04 01:29:21

以下是使用蓝牙对 Brian 的答案进行的扩展:

  1. 在 Linux 上,使用 Blueman 通过蓝牙与您的设备共享 PC 互联网:

    $ sudo apt-get install blueman
    $ blueman 经理
    配对:启用蓝牙后搜索设备
    在您的手机上并使其可见
    $ blueman 服务
    网络> [X] 网络接入点 (NAP)
    您的电话>设置>蓝牙>配对设备> [X] 互联网接入
    
  2. 使用蓝牙网络执行 ADB 命令:

    <前><代码>$ adb tcpip 5555
    $ adb connect $(adb shell ip -f inet addr show bt-pan | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9] +' | 头 -n1):5555

完成后返回 USB 模式:

$ adb disconnect
$ adb usb

注意:蓝牙 3.0 和 4.0 的速度可达 24 Mbit/s

Here's an extension to Brian's answer using Bluetooth:

  1. On Linux, use Blueman to share PC internet with your device via Bluetooth:

    $ sudo apt-get install blueman
    $ blueman-manager
    Pair them: Search devices after enabling Bluetooth
    on your phone and making it visible
    $ blueman-services
    Network > [X] Network Access Point (NAP)
    Your Phone > Settings > Bluetooth > Paired Device > [X] Internet access
    
  2. Use the Bluetooth network for ADB commands:

    $ adb tcpip 5555
    $ adb connect $(adb shell ip -f inet addr show bt-pan | egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n1):5555
    

Once done to return to USB mode:

$ adb disconnect
$ adb usb

Note: Bluetooth 3.0 and 4.0 can go up to 24 Mbit/s.

君勿笑 2024-09-04 01:29:21

步骤:

  1. su -- 切换到超级用户。
  2. setprop service.adb.tcp.port 5555 - 指定 tcp 端口 - 5555 是此处的端口号
  3. stop adbd - 停止 adbd 服务。
  4. start adbd - 启动 adbd 服务。

这与我的 Windows PC 上的 ssh 完美配合,

我尝试在我的氰基手机上启动时执行此操作,或使用 plink 启动它。使用 plink,我无法使用 su 权限启动 shell ... sudo 或 su 命令不起作用。启动时我不知道它是如何工作的!
我的 shell 程序通过 ssh 运行 su -c "sh /storage/sdcard1/start_adb.sh" 以及最后 3 个命令(不带 su --)

谢谢

Steps :

  1. su -- To switch to super user.
  2. setprop service.adb.tcp.port 5555 - To specify the tcp Port - 5555 is the port number here
  3. stop adbd - To stop the adbd service.
  4. start adbd - To start adbd service.

this works perfectly with ssh from my windows PC

I try to do this on the boot on my cyanogen mobile or launch this with plink. With plink I can't launch shell with su right ... sudo or su command not works. On boot I don't know how it's works!
My shell program works from ssh with su -c "sh /storage/sdcard1/start_adb.sh" with the last 3 commands (without su --)

Thanks

思念绕指尖 2024-09-04 01:29:21

另一项注意事项(经过惨痛教训):您不应该同时激活您公司的 VPN 连接...

One additional note (learned the hard way): You should not have your company VPN-connection active at the same time...

层林尽染 2024-09-04 01:29:21

您需要执行以下操作:

  • 首先,将 ADB 添加到您的环境路径中。
  • 在 CLI 中输入以下命令 adb connect YOUR_DEVICE_IP:PORT_NUMBER(例如 adb connect 192.168.100.100:5555

You Need to do following things:

  • First, Add ADB to your environment path.
  • From your CLI type this command adb connect YOUR_DEVICE_IP:PORT_NUMBER (example adb connect 192.168.100.100:5555)
櫻之舞 2024-09-04 01:29:21

有两种方法可以通过 TCP 连接 Android 设备与 ADB?

第一种方法

按照以下步骤操作

首先使用以下命令获取您的设备IP地址

adb shell ifconfig

以上命令的输出在

wlan0     Link encap:UNSPEC    Driver icnss
          inet addr:XXX.XXX.X.XX  Bcast:XXX.XXX.X.XXX

上面的命令的帮助下,您将找到所连接设备的IP地址

现在使用下面的命令

adb tcpip 5555

上面的命令将重新启动这个TCP端口:5555

现在使用以下命令连接您的设备

adb connect XXX.XXX.X.XXX:5555
            ^^^ ^^^ ^ ^^^
        IP Address of device

第二种方式

您可以使用 Android Studio 插件 Android device with ADB

Android WiFi ADB - IntelliJ/Android Studio 插件

IntelliJ 和 Android Studio 插件旨在通过 WiFi 快速连接您的 Android 设备,以便在无需连接 USB 的情况下安装、运行和调试您的应用程序。按一个按钮,忘记 USB 线

请查看这篇文章以获取更多信息

在 Android Studio 中将 Android 设备连接到 Wifi

There are two ways to connect your Android device with ADB over TCP?

First way

Follow this steps

First use below command to get your device IP Address

adb shell ifconfig

OUTPUT of above command

wlan0     Link encap:UNSPEC    Driver icnss
          inet addr:XXX.XXX.X.XX  Bcast:XXX.XXX.X.XXX

With the help you above command you will find the IP Address of connected device

Now use below command

adb tcpip 5555

The above command will restart this TCP port: 5555

Now use below command to connect your device

adb connect XXX.XXX.X.XXX:5555
            ^^^ ^^^ ^ ^^^
        IP Address of device

Second way

You can use Android Studio Plugin Android device with ADB

Android WiFi ADB - IntelliJ/Android Studio Plugin

IntelliJ and Android Studio plugin created to quickly connect your Android device over WiFi to install, run and debug your applications without a USB connected. Press one button and forget about your USB cable

Please check this article for more information

Connect Android Device with Wifi within Android Studio

空‖城人不在 2024-09-04 01:29:21

我正在解决同样的问题,但是
一个简单的黑客 adb 反向 tcp:; tcp: 为我工作。它允许系统接受 TCP 请求。

感谢您的阅读

I'm struct at the same issue but
a simple hack adb reverse tcp:<PORT> tcp:<PORT> worked for me. It allows the system to accept tcp requests.

Thank You for reading

戒ㄋ 2024-09-04 01:29:21

使用 adbwireless 应用程序启用手机,然后从 Windows 计算机使用 adb connect 与其通信。手机上的 adbwireless 应用程序会告诉您如何连接到它,并提供 IP 地址和所有信息。

不太有趣的替代方案是通过 USB 连接,告诉手机通过 adb tcpip 5555 使用 TCPIP,然后断开 USB,然后使用 adb connect。这要困难得多,因为这样你必须自己找出手机的 IP 地址(adbwireless 告诉你 IP),你必须通过 USB 连接,并且你必须运行 adb tcpip(adbwireless 也会处理这个问题)。

因此:在您的手机上安装 adbwireless。使用它。有可能,我经常在 Linux 和 Windows 上这样做。

Use the adbwireless app to enable the phone, then use adb connect from the Windows machine to talk to it. The adbwireless app on the phone tells you how to connect to it, giving the IP address and everything.

The much less fun alternative is to connect via USB, tell the phone to use TCPIP via adb tcpip 5555, then disconnect USB, then use adb connect. This is much harder because this way you have to figure out the IP address of the phone yourself (adbwireless tells you the IP), you have to connect via USB, and you have to run adb tcpip (adbwireless takes care of that too).

So: install adbwireless on your phone. Use it. It is possible, I do it routinely on Linux and on Windows.

墨落成白 2024-09-04 01:29:21

在我的系统上,情况是这样的:

在我的 Android 设备上的 Linux shell 中,一个简单的“ifconfig”并没有给我我的 IP 地址。我必须输入:

ifconfig eth0

- 或 -

netcfg

才能获取我的 IP 地址。 (我知道 eth0 已配置,因为我在 dmesg 中看到了它。)然后我执行了:

setprop service.adb.tcp.port -1

stop adbd

start adbd

然后在我的 Win7 机器上(运行 Eclipse 3.7.1 的机器)。我打开了命令提示符

\android-sdk\platform-tools>;

无需以管理员身份运行。然后我做了

adb connect 12.345.678.90

我从来没有放过端口。如果我执行了

adb tcpip 5555

它说找不到设备,那么我的“adb devices”列表中什么也没有出现。也就是说,只有当我不执行上面的 tcpip 命令时它才有效。

我可以做一个“adb shell”并搞乱我的 Android 设备。但我的 Android 设备现在没有出现在我的“运行”->“运行配置”->“目标”选项卡中。另一方面,如果我将目标选项卡设置为自动。然后,当我通过“运行”->“运行”运行我的应用程序时,它确实在我的 Android 设备上运行,即使我的 Android 设备甚至没有被列为我的目标之一。

On my system it went like this:

On my Android device in my Linux shell, a simple "ifconfig" did not give me my IP address. I had to type:

ifconfig eth0

-or-

netcfg

to get my IP address. (I knew eth0 was configured because I saw it in my dmesg.) Then I did the :

setprop service.adb.tcp.port -1

stop adbd

start adbd

Then on my Win7 box (the one running Eclipse 3.7.1). I opened a command prompt to

\android-sdk\platform-tools>

without running as admin. Then I did a

adb connect 12.345.678.90

I never put a port. If I did a

adb tcpip 5555

it said it couldn't find the device then nothing appeared in my "adb devices" list. I.e. it only works if I DON'T do the tcpip command above.

I can do an "adb shell" and mess with my Android Device. But my Android Device does not appear in my Run->Run Configurations->Target tab right now. On the other hand, if I keep the Target Tab set to automatic. Then when I run my app via Run->Run it does run on my Android device even though my Android device is not even listed as one of my targets.

梦里的微风 2024-09-04 01:29:21

我确实让这个工作了。没有使用任何 USB 电缆。

  • 应用adb无线。
  • 运行它。这将设置 ip 和端口;然后在dos中

    cd C:\Program Files\Android\android-sdk\platform-tools adb connect "192.168.2.22:8000 "enter"
    

连接。

I did get this working. Didn't use any usb cable.

  • app adb wireless.
  • Run it. That will set ip and port; Then in dos

    cd C:\Program Files\Android\android-sdk\platform-tools adb connect "192.168.2.22:8000 "enter"
    

Connected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文