Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money

introduce

In our development process, we usually use Usb cable to connect the App when debugging, which has several problems

  1. If the quality of the line is not good, it is often easy to fail to connect.
  2. If the interface is loose, it is often easy to connect to the situation.
  3. If you have multiple devices debugging together, you need a lot of lines, and the desktop can easily become messy.

We usually think about using wifi to connect to our phones

WiFi Connectivity (before Android 11)

Before Android 11, if you use WiFi connection, you need to use USB connection first

Then we use terminal connection

  1. Connect the Android device and adb host to the same WLAN that both can access. Please note that not all access points are applicable; You may need to use an access point whose firewall is properly configured to support ADB.

  2. If you want to connect to a Wear OS device, turn off the Bluetooth on your phone that pairs with that device.

  3. Connect the device to the host using a USB cable.

  4. Set up the target device to listen for TCP/IP connections on port 5555.

    adb tcpip 5555
    Copy the code
  5. Remove the USB cable from the target device.

  6. Find the IP address of the Android device. For example, for Nexus devices, you can go to Settings > About Tablet (or About Phone) > Status > IP Address to find the IP address. Alternatively, for Wear OS devices, you can go to Settings > WLAN Settings > Advanced > IP Address to find the IP address.

  7. Connect to the device through the IP address.

We can see that this is still quite cumbersome, so someone made a plug-in called WiFi adb, after installing it, we can open the plug-in connection interface in Android Studio > Tools> WiFi adb >, as shown below:

The operation is also very simple, he will list the current connected USB phone, and then there is a status, if it is not connected, there is a connect button, click it will automatically help us to connect.

WiFi Connectivity (after Android 11)

If we’re running Android 11 or higher, it’s even more convenient. Android Studio comes with WiFi connectivity, no additional ADB plug-in required, and no data cable required.

First of all, we can find the item of wireless debugging in the developer option of the mobile phone. We can just turn on the switch.

Click into it, we can see that the interface lists the device name, IP and port. In the operation bar below, there are two options: one is to use qr code to scan the pair, the other is to use the pair code to pair the pair

Let’s click on it

At this time, we just need to open the following Settings in Android Studio interface, there is a Pair device Using WiFi

We click, we can see, and mobile phone, is also the use of a TWO-DIMENSIONAL code, a pair of code

It is very simple. If qr code is used for pairing, we can scan the QR code provided by Android Studio with our mobile phone, and if the matching code is used for pairing, we can enter the matching code provided by our mobile phone.

reference

Android debug bridge (adb) | | Android Developers Android Developers