Forum Visual Studio

Android Emulator from Host Device inside Windows VM

That title might be confusing... Let me try to clear it up. I am using a Mac with Windows installed in a Parallels VM for Visual Studio. I suspect that running an Android emulator in my host (Mac) will perform better than an emulator running in the already virtual Windows instance. I am using HAXM for my Android emulators on my Mac and they are very responsive (comparatively).

When I open Visual Studio, I don't see my running emulator(s) listed and they are not listed when I run "adb devices". Is it even possible to do this? If so, does anyone have any advice for making it work out?

Thanks in advance! Also, if this is still confusing, I'm happy to provide additional details.


  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai

    Interesting question. I was wondering about this myself recently, so I tried a few experiments today and found at least one way that seemed to work for me. I wrote up the steps as a knowledge base article here:

    If you like, feel free to try the technique under "Google Android emulators" and let me know if "vnic0" is indeed the correct name of the "Shared Networking" network interface in Parallels.

  • DylanStrugeonDylanStrugeon USMember ✭✭

    Thanks for the quick reply! As an important side note, I am using Windows 10 Tech Preview so it's entirely possible that the answer is "it doesn't work in Windows 10 at the moment" and I don't want to waste a lot of your time.

    I followed the instructions, but it doesn't seem to be working. adb in Windows responds with "unable to connect to [my ip address]". It also seems to implicitly add port 5555 to the address: when if enter "adb connect" it would respond with "unable to connect to" and then if I enter "adb connect" it would respond with "unable to connect to" which seems strange (I didn't actually use localhost, just an example here).

    I tried with vnic0 and vnic1 (restarting in between), but neither worked. I have the VM's network interface type set to 'Shared Network'. Is the NIC important?

    I also don't really understand the command in step 4 (I get the idea, but my shell-fu is very weak), so I'm not sure how to troubleshoot.

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai

    The duplicated port address is just a quirk of how adb displays things when there's an error. That can be ignored.

    As an intermediate debugging step, you could try connecting to the emulator from the Mac using the same adb connect statement you're trying on Windows (that is, using the full IP address from ifconfig vnic0 | grep 'inet '). You can also test if your Mac is really allowing connections on that port at all by using telnet on the Mac. For example telnet ip-address-of-the-mac 5555. If that prints out:

    telnet: Unable to connect to remote host

    ... then either the redirect command in step 4 was somehow unsuccessful, or the emulator isn't currently listening on "localhost:5555".

    The command in step 4 is just a slightly fancy way of doing:

    echo 'rdr pass on vnic0 inet proto tcp from any to any port 5555 -> port 5555' | sudo pfctl -ef -

    (See for a few more similar examples that might help show the intention of this line. You could duplicate the line if you wanted and change the second line to use vnic1. That way the rule would be applied to both network interfaces.)

    The command in the original step 4 uses sed instead of echo so that it can add the new redirect in addition to the default system pfctl rules that are stored in /etc/pf.conf, rather than replacing them. In my tests, running pfctl either with or without /etc/pf.conf both seemed to work OK for this particular case of connecting to the Android emulators.

  • DylanStrugeonDylanStrugeon USMember ✭✭

    I gave both your debugging steps a shot. Using adb connect on the Mac still fails, with the same error. I then tried to telnet to the address, to which I received 2 error messages: "connect to address [vnic0 ip address]: Permission denied" followed by "Unable to connect to remote host". I tried to give telnet a 'sudo', in case it was just account permissions (a shot in the dark), but get the same response.

    From that, I guess the port forwarding must not be working correctly for me. Below is the output from the step 4 command, in case anything in there is indicative of an error:

    pfctl: Use of -f option, could result in flushing of rules
    present in the main ruleset added by the system at startup.
    See /etc/pf.conf for further details.
    No ALTQ support in kernel
    ALTQ related functions disabled
    pfctl: pf already enabled

    I will do some snooping into this, but I suspect you might have some insight as well. Thanks for all your help!

  • PeterDouglasPeterDouglas USUniversity ✭✭

    I got this as well, but it connected when I specified the port 5555 in the ABD command, eg.,

  • dastarnesdastarnes USMember

    So this worked for me using VirtualBox with a Windows 8.1 guest. I had a little trouble with the pf.conf file but that's because this is the first encounter I've had with sed. After I figured out what the command did I edited the file with vim. The only other change was the name of the interface I am using in VirtualBox is en0 which is the AirPort interface which is Apple-speak for wifi. Everything else worked as stated. And it was much easier that I expected. So I am happy.

  • MathieuFillionMathieuFillion USUniversity
    edited March 2017

    @BrendanZagaeski I followed your article, with option 1 (nc), I'm then able to connect from windows to the emulator (the adb connect command returns "connected to [...]") but it says it's offline when I type "adb devices" in the windows command prompt even though it's running on the mac. Visual Studio also doesn't list that emulator as an available device.

    I double-checked with ifconfig, the loopback address of the mac is and the ports used by the emulator are 5556 and 5557, so I used 5557 instead of 5555 in your article.

  • BrendanZagaeskiBrendanZagaeski USForum Administrator, Xamarin Team Xamurai

    but it says it's offline when I type "adb devices" in the windows command prompt even though it's running on the mac

    The first thing that comes to mind for that is to try running adb kill-server once more the Mac to make sure the adb server didn't start back up over there, and then perhaps disconnect and reconnect via adb on Windows. I've noticed the "offline" status for the emulator on Windows if the Mac adb is still connected to it.

  • MathieuFillionMathieuFillion USUniversity

    @BrendanZagaeski it was exactly that, it seems I need to kill the adb server again on the mac after I run the "nc" command. The device is then listed as "online" and Visual studio offers it as a choice of deployment device.


  • valdeterovaldetero USInsider, University ✭✭

    For anybody that comes to the post in the future. The emulator CANNOT have Google Play Store enabled. It can be x86 or x64, it can have Google APIs, but not Google Play selected. You will get "unauthorized" when running adb devices from the windows machine.

Sign In or Register to comment.