Debugging allows us to see our app's flow and to find and fix errors. Let’s see how to do this with Xamarin on an Android device.
When we are developing an application, we usually need to use debug mode, either because we have an error and want to see what exactly is happening or just because we want to see the internal behavior of some action .🤷
Thanks to this tool, we are able to see the flow of the application in real time step by step. But how do we do this with Xamarin for Android in Visual Studio? In this post we’ll be learning just that! The topics will be divided in the following points:
🔹 What is a debugger?
🔹 Set up a device for development
🔹 Preparing the Android device
🔹 Installing USB drivers
🔹Testing the device on the computer
It’s a tool included in most IDEs that helps us find and fix errors in program code. With this tool we can see, step by step, all the internal execution of methods inside our application to perform a certain action, allowing us to see even the value that each variable is getting at a given time while the debugger is running.
The best option we have to test an app is to test it on a physical device. For this, we just need to follow two main steps to apply a specific setting in our device and computer.
Prepare the Android device
Install USB drivers (This step is only for Windows. MacOS users don’t need this.)
Knowing the basic steps to complete, let’s start detailing them one by one!
The first that we have to do is to enable debug mode in our Android device. We have two ways to do this, depending on the Android version of the device:
For Android 4.0 to Android 4.1
For Android 4.2 and higher
Once our device is to enabled to debug, we have to install USB drivers.
⚠ It’s important to know that this step is only for Windows—you don't need it on Mac.
Step 1: Running the android.bat application
By default, the Android installer puts the Android SDK in following location on a Windows computer:
⚠ Please take into account that in some cases, some of these folders are hidden and you will have to show hidden folders in Windows.
Step 2: Downloading USB drivers
All Android devices should use the USB driver from their respective manufacturer, with the exception of Google Nexus devices, which require specific drivers for their use, found here.
To install the Google USB Driver package, you have to start the SDK manager, expand the “Extra” folder, check the Google USB Driver option, and finally push the Install button.
Step 3: Installing USB drivers
To install the driver, you must apply the following points:
First of all, you have to be sure that ADB is installed on your computer. But if it’s not installed, you can download it here.
Let’s learn how to do it:
Step 1: Enter the letter Y in response to “Do you want to install ADB and Fastboot?”
Step 2: Enter the letter Y in response to “Install ADB system-wide?”
Step 3: Enter the letter Y in response to “Do you want to install device drivers?”
Step 4: And finally an installation wizard will appear. You click Next until finished.
And now, we can start testing our device! 😎
We have two ways to do it: USB Cable or WiFi.
➖ Connecting with the USB Cable: Just connect your device to your computer and it will be available to debug! (Your device gets this as a default way.)
➖ Connecting with WiFi: Another way is to connect through a Wifi network, which is very useful because we don’t have to have the cell phone connected to a USB cable, and it allows us to have a further distance between the device and the computer. To do this, you must follow the following steps:
adb tcpip 5555.
adb connect XXX.XXX.X.XXX:5555(Your_IPAdress:5555)
And done! Our device has gotten WiFi connection! 😎
Finally, our debug mode is enabled both Visual Studio For Mac and for Windows. It should look like this:
That’s all for today! I hope this article is useful for you!
Thanks for reading! 💚
Leomaris Reyes is a Software Engineer from the Dominican Republic, with more than 5 years of experience. A Xamarin Certified Mobile Developer, she is also the founder of Stemelle, an entity that works with software developers, training and mentoring with a main goal of including women in Tech. Leomaris really loves learning new things! 💚💕 You can follow her: Twitter, LinkedIn , AskXammy and Medium.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.