可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I want to connect to the Android device using adb
over the network. I am familiar with How can I connect to Android with ADB over TCP? and with https://developer.android.com/guide/topics/usb/index.html and follow the guidelines. Specifically, I did the following:
# adb kill-server # adb tcpip 5555 * daemon not running. starting it now on port 5037 * * daemon started successfully * restarting in TCP mode port: 5555 # adb connect 192.168.1.101:5555 unable to connect to 192.168.1.101:5555:5555
Due to the last error, I also tried
# adb connect 192.168.1.101 unable to connect to 192.168.1.101:5555
I also tried to restart the device itself, but it did not help. Any reason why it does not work?
Update: To clear any doubts, I am sure that this is my device internal IP address.
回答1:
I've been having the same issue with my unrooted device. And contrary to popular belief it seems that adb tcpip <port>
requires either an emulator or a debug build or root privileges; at least according to the source code.
master branch: https://github.com/android/platform_system_core/blob/master/adb/adb.c#L898 look at should_drop_privileges
which prevents https://github.com/android/platform_system_core/blob/master/adb/adb.c#L966 adb_main
to open a TCP/IP socket connection.
In older branches the logic for identifying the privileges of adbd
were in adb_main
itself. See: https://github.com/android/platform_system_core/blob/froyo-release/adb/adb.c#L860
So, to further prove that adbd
won't enter TCP/IP mode (even though adb tcpip
gives out no errors), look at the following:
adb shell getprop | grep 'ro.secure\|debuggable\|qemu'
, output for my device:
[ro.secure]: [1] [ro.debuggable]: [0]
This does not meet the conditions of being able to get a secure
value of 0 in adbd
, since I'm not running an emulator (which needs TCP/IP by default), I'm not running a debuggable build of Android, and I'm not root.
Furthermore if you issue an adb shell netstat
command you'll see that there's nobody listening on port 5037 or 5555 or whatever else you supplied to the tcpip
command as expected from an adbd
running in TCP/IP mode.
Hope this helps, good luck!
回答2:
The ability to restart adbd using tcpip transport can vary from device to device. Without knowing exactly which device you're using it's very difficult to know the exact cause.
I tested "adb tcpip 5555" on a Galaxy Nexus (takju) running 4.2.1 and found it to work. I also tested on a couple other devices and those did not work.
I managed to get it to work using root access on a Motorola Droid 3. Note that ro.secure=1 and ro.debuggable=0 still. I simply by manually set service.adb.tcp.port" to "5555" as such:
devbox:~/droid3$ adb shell shell@cdma_solana:/$ getprop | grep 'ro.secure\|debuggable\|qemu' [ro.secure]: [1] [ro.debuggable]: [0] shell@cdma_solana:/$ su -c 'setprop service.adb.tcp.port 5555' shell@cdma_solana:/$ exit devbox:~/droid3$ adb tcpip 5555 restarting in TCP mode port: 5555 devbox:~/droid3$ adb connect 172.16.0.14 connected to 172.16.0.14:5555 devbox:~/droid3$ adb -s 172.16.0.14:5555 shell shell@cdma_solana:/$
Although I specified 5555 when running "adb tcpip" it gets ignored by the device. It seems that this particular device does not have the required access to set the "service.adb.tcp.port" property without root.
Similarly, you can go back to USB as such:
shell@cdma_solana:/$ getprop | grep adb [persist.service.adb.enable]: [1] [ro.sys.atvc_allow_all_adb]: [0] [persist.adb.tcp.port]: [] [init.svc.adbd]: [running] [service.adb.tcp.port]: [5555] shell@cdma_solana:/$ su -c 'setprop service.adb.tcp.port ""' shell@cdma_solana:/$ exit devbox:~/droid3$ adb -s 172.16.0.14:5555 usb restarting in USB mode devbox:~/droid3$ adb shell shell@cdma_solana:/$
The reasons that this might not work on other devices vary.
On the Galaxy Nexus I tested, the shell user is able to set the "service.adb.tcp.port" property. It's not clear why this differs at this time.
Interestingly it seems the droid3 will not continue to listen on USB if you enable TCPIP. However, the Galaxy Nexus will.
Hope this helps..
PS. See also: How can I connect to Android with ADB over TCP?
回答3:
I also met same scenario as your, TCPIP setup succeseed, but adb connet failed. I finally found it's my network problem, the ping also failed under that scenairo. After i made the ping works, the adb connect works as well. So, my suggestion is to check your network environment.
回答4:
Hi there I know this is an old question but I was having the same problem. I am not sure it is the same case for you but the problem for me was that I was connecting my Android device through a USB expansion, as soon as I connected the Android device directly to the USB port in my MAC it worked.
Just to clarify try to connect the Android device directly to the computer or try switching the USB port.