Working with Xamarin enables us to create cross platform applications in a breeze but when we debug we need at least an emulator/device per platform 😀
The problem is that we need a lot or RAM & CPU power on our machine to emulate all the devices we need and often laptops suffer from this.
In my case, I use a 13″ MacBookPro with 16Gb of ram with OSX on which I have installed the iOS & Android emulators and Windows 10 (through Parallels) with VisualStudio 15.
Everything works pretty well, thanks to the Mac agent I can connect to the iOS emulator directly from Windows but how can I use the Android emulator from Visual Studio and avoid reinstalling it in Windows and use nested virtualization?
REMOTE ANDROID DEBUGGING
What we want to do is basically what the Xamarin Mac Agent does for the iOS emulator: open an SSH connection to OSX and do a port forwarding.
In this way Windows will see the Android emulator like it is running directly on his pc.
Remember that it doesn’t matter that I’m running the two OSs on the same machine as they think they are separate machines on the same network!
To do this we need to install OpenSSH on the windows machine (you can get it here) and then connect to our machine running the Android emulator (that can be any OS we want as long it supports SSH) using the Command Prompt and the following command (remember not to close this window as it will close also the connection):
- 5554 & 5555 are the ports on the machine that has the emulator running
- localhost:5554 & localhost:5555 are the ports on the Windows machine to which we are binding, the syntax is:
- email@example.com is the username of the account of the machine that has the emulator and it’s ip address in the network
i’m using ports 5554 & 5555 because my android emulator uses this port, you can check which port it is using with
keeping in mind that since the emulator is 5554, its local loopback port is 5555 (always emulator port + 1)
MAC OS X SSH USER
To enable SSH on MAC OS X go to SystemPreferences -> Sharing and enable “Remote Login”
KILLING ADB SERVER
Once we have established the connection to the SSH server we need to kill the adb server on the machine that hosts the emulator so that it will be available for other machines.
Now the status of the emulator will pass from “offline” to “device” and et voilà in Visual Studio it will automatically appear in the list of devices we can deploy to 🙂
If you found this post useful consider nominating me for the MVP Award 🙂