Wireless Debugging on Android Devices

I have published my application named 'Coğrafya İnteraktif Harita', which is one of the mobile applications I developed over the last two weeks. 

I am writing this blog post to document the fast debugging method I use during development. I mean, this is not exactly a secret, but it might serve as useful information for those who are unaware of it or haven't realized it yet.

Under normal circumstances, debugging through the Android simulator provided by Android Studio or standalone emulators can be painful depending on your environment. In contrast, debugging directly on a real Android phone is highly fast and comfortable. Of course, this situation might also vary depending on the size of the application. Anyway, I remember that in the past, I had to connect my phone to the computer to debug; because the connection was constantly dropping—whether due to the USB cable itself or the computer's erratic behavior—the debugging process turned into a complete ordeal for me and really put me off. After a long time, when I returned to mobile development for a small application, I joyfully experienced that there was actually no need for this cable situation at all. The solution is 'Wireless Debugging'. Back then, my old Android device probably did not feature such a function, so I couldn't benefit from this blessing. Anyway, without further ado, let's see how Wireless Debugging is done using ADB.

Note: Both your computer and your Android device must be connected to the same Wi-Fi network

First, let's open the command prompt on your Windows computer:

C:\Users\gurbu>adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
First, I performed a routine check to see if any device was connected, and it appears that none are. Now, let's open the Android phone; you will likely access the required settings section on your phone in a similar manner.

Wireless Debugging on Android Devices

Open the Wireless Debugging.
Wireless Debugging on Android Devices
Make sure 'USB debugging' and 'Wireless debugging' are selected. Additionally, press and hold 'Wireless debugging' to open the following page:
Wireless Debugging on Android Devices

The sections that concern us here are the 'IP address & Port' section and the 'Pair device with pairing code' section. First, click on 'Pair device with pairing code':

Wireless Debugging on Android Devices
Now, I want to pair the devices according to the information provided above, as shown in the command prompt below:

C:\Users\gurbu>adb pair 192.168.1.102:44749
Enter pairing code: 611794
Successfully paired to 192.168.1.102:44749 [guid=adb-XXXXXXXXXXX-XXX]
I have completed the pairing process; once paired, your computer should already appear listed under the 'paired devices' list.

Wireless Debugging on Android Devices

Now we can connect to this Android device from our computer wirelessly. This time, we enter the IP and port information written under the 'IP address & Port' section. Note: This is not the IP address and port that we used during pairing; take a close look at my screenshots.
C:\Users\gurbu>adb connect 192.168.1.102:32979
connected to 192.168.1.102:32979
It appears that we have successfully connected; let's check the devices list once again:
C:\Users\gurbu>adb devices
List of devices attached
192.168.1.102:32979     device
adb-xxxxxxxxxxxxx._adb-tls-connect._tcp       device
Our device has now been successfully connected to the computer wirelessly for debugging.

We can also see that the device is visible and ready to be used on Visual Studio.
Wireless Debugging on Android Devices Visual Studio

No comments:

Post a Comment