Testing, Debugging and Deploying Android Applications Using Xamarin Across Wears and Handheld Devices


In my previous article we talked about how to create an app in Wearable and Handheld devices and create a simple implementation of sending/syncing data. In this article show how to deploy and test apps in real devices. First of all I am using a Nexus 9 and a LG G Watch as my test devices.

Before we start, make sure that USB Driver for Android is installed in your machine. You can verify it by right-clicking on the COMPUTER > MANAGE > DEVICE MANAGER > OTHER DEVICES. If the driver isn't in the list then you must download the driver here: http://developer.android.com/sdk/win-usb.html and refer to this link for the installation guide: http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver

The next important thing is to enable USB Debugging in your handheld device. You can enable it under SETTINGS > DEVELOPER OPTIONS > USB DEBUGGING. Once you have the required driver installed and you have enabled debugging for your device then just plug your handheld device into your PC or laptop. In Visual Studio you should be able to see the connected handheld device as shown in the image below:

Deploying the App to Handheld device

The following is the procedure for deploying the app:

  • Right-click on the main app project and select PROPERTIES > ANDROID OPTIONS. Under the Packaging tab uncheck the "Use Fast Deployment (debug mode only)".

  • Under the Packaging tab uncheck the "Use Fast Deployment (debug mode only)".

  • Unload the project.

  • Edit the .CSPROJ file and add this PropertyGroup:
  1. <PropertyGroup>  
  2.    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>  
  3. </PropertyGroup>  
  • Save and then load the project.  
  • Right-click on the main app project and set it as the startup project.
  • Build the app.
  • And then click run or the Play button. This will package and install the app to the device. Just wait for it to finish.
Deploying the Wear App

You can follow the same procedure for deploying the wear app just as was done for the main app. If you want to deploy and debug your app over Bluetooth then here are the extra steps:
  • Open the Android Wear companion app in your handheld device.
  • Tap the menu on the top right and select SETTINGS.
  • Enable "Debugging Over Bluetooth". You should be able to see the status like this:             
  1. Host: disconnected  
  2. Target: connected  
  • Connect the handheld to your PC or laptop over USB.
  • In Visual Studio, go to TOOLS > ANDROID > ANDROID ADB COMMAND PROMPT and run the following commands:            
  1. adb forward tcp:4444 localabstract:/adb-hub  
  2. adb connect localhost:4444  
  • You should then be able to see the wear device in the device list as shown in the image below: 

  • Repeat the same steps 1-5 mentioned in Deploying App to Handheld device.
  • Now set your Wear App as the startup project, build the app and run. 
Once installed you should be able to set a breakpoint in Visual Studio to do the debugging and test your application. Here's the output of the sample application:

You can see the demo project on Github in case you want to see and run the demo project about syncing data between wearable and handheld device. Here's the link:

If you are new to Android development and would like to explore it using Xamarin and Visual Studio then you can check my previous article about:

Getting Started with Android Wearable using Xamarin and Visual Studio.

That's it! I hope someone finds this article useful!

Similar Articles