Microsoft needs to fix its Android emulator

Microsoft wants Windows 10 to be an ideal developer operating system, with its Linux subsystem, and Visual Studio 2017 is notable for its strong cross-platform development tools.

There is an annoyance though. Google’s Android SDK includes an emulator for debugging mobile applications, but it requires hardware acceleration in the form of Intel’s HAXM (Hardware Accelerated Execution Manager). Otherwise you get an error as below:

image

Unfortunately this is incompatible with Hyper-V, the hypervisor built into Windows. You cannot fix this by stopping Hyper-V services; it is set when Windows boots.

Hyper-V is increasingly important for general Windows developers. It is not only useful for running up VMs on which to test stuff, but also for the official Docker tools and testing Windows containers.

The solution should be to use the Visual Studio Emulator for Android. This is based on Hyper-V so no problem.

Unfortunately it does not currently work very well. On one of my PCs it starts, but without internet connectivity, rendering it useless for many apps. On another PC it does not start at all.

image

I spent a bit of time trying to get it to work. The networking problem seems to be related to conflicts with other applications using Hyper-V. Specifically, the Visual Studio Emulator for Android uses two Hyper-V virtual network adapters, one connected to the Windows Phone Emulator Internal Switch, and the other connected to an external virtual switch. This second adapter gets its network settings using DHCP (there is no way to change this). The emulator app proxies internet connections from the internal to the external network.

The reference to Windows Phone comes about because this is essentially the Windows Phone emulator adapted to run Android.

In my Hyper-V setup I have another internal switch, called DockerNAT, used by the Docker tools, as well as a third internal switch which I’ve used for other things. In the emulator’s network settings I can actually see four Desktop Adapters (in addition to the primary “Emulator adapter”, of which only one has internet connectivity via my business network. I theorised that the emulator is attempting to proxy via the wrong adapter, and disabled the others in Control Panel – Network Connections. However it still does not connect.

Judging by posts like this and this, there may be some cocktail of settings in Hyper-V and in Control Panel that gets this working. Bear in mind though that I want everything else to work too.

I also note that Windows developer evangelist Scott Hanselman suggests setting up a dual boot arrangement so that you can boot with HAXM enabled when you want to develop on Android, and with Hyper-V otherwise – implying that there is no other easy fix.

This works, though it is a dreadful solution. Rebooting is not only time-consuming, but disruptive to the flow of your work, and having to reboot with special settings just to work on Android is painful.

It strikes me that this could be fixed with a bit of effort. If Microsoft is serious about persuading developers to use Windows 10, Visual Studio and Xamarin for cross-platform mobile apps, that would be a good idea.

Related posts:

  1. Windows Phone 7 emulator yields its secrets
  2. How to run Android Studio on Windows without disabling Hyper-V
  3. Half-baked Android tablets will help Apple, give hope to Microsoft
  4. Microsoft Build goes nuts over Xamarin’s C# and .NET for iOS and Android
  5. Android up, Apple down, Microsoft so near, so far: 2012 in review

6 comments on this post.
  1. Niclas Lindgren:

    I have never had any issue with Microsoft android emulator and quite foreign to your problems, never seen any of them actually and I run win10 on stable and fast rings. It is much faster than the Google one (now, as today, google’s is better though, but..). As I have not seen them, I suspect the problem is some combination of things on your computer.

    That said, fast ring at the moment is slightly unstable as an OS.

    The biggest issue with the Microsoft emulator (and any non google) has more been that it is rather tedious to get Google play to work however, this is though probably slightly out of Microsoft’s hands.

    Hanselman’s suggestion is from before you had the emulator and before windows 10. I have the same setup, but this is because of virtual box not really because of any issue with Hyper-V

  2. Ben Armstrong:

    Hi Tim,

    Ben Armstrong – from the Hyper-V team here. This is definitely something that we want to do a better job of – but I recently went through this process myself. I have a blog here that talks about how I got everything setup: https://blogs.msdn.microsoft.com/virtual_pc_guy/2017/03/20/phone-emulator-containers-vms-networking-finally-working/

    Cheers,
    Ben

  3. tim:

    @Niclas glad it is working but issues are widespread – check the comments here for example:

    https://www.thurrott.com/forums/microsoft/dev/thread/xamarin-challenge

    Tim

  4. tim:

    @Ben thanks for the tip. Unfortunately in my case it didn’t help. On PC A it runs but without internet connectivity. On PC B it hangs for ages on “OS is starting”, then gives an error “Couldn’t auto-detect the guest IP address.” DCHP is used everywhere so it is not that.

    Tim

  5. PJ Bryant:

    Tim, experiencede similar issues, but have finally moved on a bit after some experimentation and finally (today) having done the following:
    After installing VS2017 (using the options needed for Xamarin challenge), started the Android SDK Manager (run As Administrator) and updated everything before going any further.
    Then after loading the Xamarin Challenge part 1, the build worked for the first time since trying.
    On the first run of the modified build (step 18) I got a request to elevate the Android emulator due to HyperV issues, and it all worked.
    Up to this point the Xamarin project failed event to build on 2 different machines.
    One machine is 1607 fully patched, the other 1703 (likewise). It’s worked on the 1607 build.

    I guess, as ever with windows machines, YMMV

  6. Carel Lotz:

    Another big frustration is that these emulators are slow to get updates for the latest Android SDK updates. Currently only API 23 is supported with both API 24 and API 25 being available for quite a while now. Here’s the UserVoice request – https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/16799356-support-android-api-level-24

Leave a comment