[Android] New posture for real machine debugging: wireless connection

Due to the needs of the work, it is necessary to connect the mobile phone wirelessly to debug, and Baidu deliberately

When developing Android, we generally use usb cable to connect the mobile phone and computer for debugging. But if that's not cool enough for you, try a wireless connection, it's easy, GO!

Ready to work

  • The phone and computer need to be on the same local area network
  • Prepare a data cable - (what? Don't you mean wireless connection?! Don't worry, this is only used when setting up for the first time, and you won't need a data cable if you connect it later)
  • You need to know how to execute the adb command (if you don't know, please Google it yourself)

Start

1. Open port 5555 of your phone

Allow the phone to receive TCP/IP connections on the specified port. (Of course, you can also use 5555, 5556 or 9999, etc., as long as you like)

  1. Make sure your phone has usb debugging enabled
  2. Connect phone to computer with usb cable
  3. Excuting an order: 
    adb tcpip 5555

After successful execution, you can unplug the usb cable.

2. Find the IP address of the phone

Generally, it can be found in Settings - About Phone - Status Information - IP Address. 
For example, I see here that the IP address of the mobile phone is 192.168.1.108

3. Connect the phone by IP address and port

Excuting an order: 
adb connect 192.168.1.108:5555

To disconnect, execute:

adb disconnect 192.168.1.108:5555

3.1 If prompted

connected to 192.168.1.108:5555

it means the connection is successful

3.2 If prompted

unable to connect to 192.168.1.108:5555: Operation timed out

- Maybe your IP address is wrong; or the adb service is unavailable; or the phone and the computer are not in the same local area network correctly; or the link is blocked by the proxy, etc...

3.3 If prompted

unable to connect to 192.168.1.108:5555: Connection refused

——Maybe your phone's port 5555 is not properly opened; or there is a firewall blocking it, etc...

4. If the connection is not successful

If there is an error message of 3.2 or 3.3, or any other error, you can try to restart the adb service:

adb kill-server

Then try again.

5. The connection is successful

If the connection is successful, execute the following command to view the list of currently connected devices: 
adb devices 
You can see the connected devices, like this

$ adb devices 
List of devices attached 
192.168.1.108:5555 device

——Congratulations, you can get rid of the dependence on the data line from now on.

Summary & Others

    1. To change a network environment (such as bringing your mobile phone and computer home from the company), you generally only need to reconnect according to the new mobile phone IP.
    2. But if the phone restarts, you need to reconnect the data cable to open the 5555 port again.
    3. Of course, it is not necessary to open port 5555 through adb. There are also some methods to open it directly on the mobile phone. But these methods generally require root permissions, if you want to try to open it on your phone, please pay attention to safety.
    4. There are pros and cons - wireless debugging has advantages over wired debugging, but the disadvantage is that wireless data transmission will be slower than wired.
    5. Another point, since I used wireless debugging, my test machine that has been fully charged all the year round now needs to be charged from time to time~~~ 
      o(╯□╰)o

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324781080&siteId=291194637