Xamarin.Android – debugging via WiFi

In this short post, I’m going to show you a very handy feature of Android Debug Bridge (adb) – possibility to debug Xamarin.Android apps in Visual Studio via WiFi connection.

Using ADB to debug Android apps

By default, adb is configured to “map” Android devices connected via USB ports to the computer as debug devices, which are then available e.g. in Visual Studio as the device on which our app can be deployed and debugged. In may cases we debug apps on Android emulators, which is frequently fair enough, but at some point we need to make our tests on a physical device.

It may not be very comfortable to have the phone connected using USB cable all the time, especially when testing some physical sensors like accelerometer or gyroscope. For such purposes, ADB gives us the possibility to connect Android devices via WiFi instead of USB. Let’s see how to configure it.

Configure ADB to work on WiFi

The first requirement is – obviously – that both our development PC and Android device must be connected to the same WiFi network. Then we need to find out what is the IP address of our Android device – it can be checked by going to Settings -> WiFi -> Menu – Advanced settings (Android 6.0):

Android 6.0 – IP address

As soon as you have IP address of the device noted, connect it to the computer via USB port.

Now we need to use adb.exe to configure it for connecting with the device via WiFi. You can either add system environmental variable pointing to where the adb.exe is stored or just open cmd, go to the catalogue where it’s located (Android\platform-tools\) and execute the following commands:

  1. Change ADB to listen on TCP port:
adb tcpip 5555

This will make ADB listening on TCP port 5555 instead of USB ports (NOTE: since now the computer won’t listen to any devices connected by USB ports):

Now, disconnect the Android device from USB port.

2. Make ADB connect to your Android device:

adb connect 192.168.0.101:5555

This command is used to connect to Android device (of course IP address must be changed with your device’s one) on port 5555 using WiFi:

3. Since now you should see the device in Visual Studio connected using WiFi connection:

WiFi Android device visible in Visual Studio

and you can of course deploy the app remotely on the device and debug it 😉

4. As soon as you’re done with WiFi debugging, run the following command:

adb usb

It will make ADB listening for USB devices again:

TIP: if during performing any cmd commands adb.exe is stuck or not reacting, try plugging out and re-plugging in your Android device to USB port.

Summary

This post described how to use remote debugging on Android devices using WiFi connection.

I hope you’ll find it useful 🙂

.NET full stack web developer & digital nomad
0 0 votes
Article Rating
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Stuart
Stuart
6 years ago

Why are there no comments on this post! You should have billions of people thanking you for this awesome advice! Cheers!!!!

PJ
PJ
6 years ago

Worked like a charm, thank you so much!