42

Can I run Android Studio and Android SDK emulator in a Microsoft hyper-v virtual machine? Please read carefully.

I already use Hyper-V a lot for other purposes. Now I need to develop a app for Android.

I've installed a new virtual machine (windows 10) and installed Android Studio. I cannot run the android emulator because it's lacking the 'intel HAXM software'.

I read a lot about that it's not possible to install Hyper-V NEXT to Android Studio, but non of the post actually say anything about installing in a Hyper-V machine.

Dennis
  • 1,528
  • 2
  • 16
  • 31
  • 1
    Can you, in general, run a virtual machine inside hyper v? Because that's essentially what you're doing – OneCricketeer Feb 09 '16 at 13:44
  • 3
    "Can I run Android Studio in a Microsoft hyper-v virtual machine?" -- that should be OK. However, that is not your problem. "I cannot run the android emulator because it's lacking the 'intel HAXM software'." -- Android Studio is not your problem. The Android SDK emulator is your problem. The ARM emulator images may work inside your virtual machine, but they will be very slow. I doubt that the x86 emulator images will work inside your virtual machine. Either test your app on Android hardware, or try a third-party emulator, like Genymotion. – CommonsWare Feb 09 '16 at 13:46
  • 1
    Understood, so in short the answer is: no ?! – Dennis Feb 09 '16 at 13:59
  • 2
    Android Emulator support for Hyper-V acceleration is currently in preview. This should remove the need to use Microsoft's android emulator, or run the emulator in a nested virtual machine. See this blog for details: https://blogs.msdn.microsoft.com/visualstudio/2018/05/08/hyper-v-android-emulator-support/ – joslack Jul 02 '18 at 23:19

7 Answers7

53

Refer to this link: How to run Android Studio on Windows without disabling Hyper-V

The solution (if you do not want to disable Hyper-V) is to use Microsoft’s Android emulator, which is a free download here.

In order to use this with Android Studio, you need to run the emulator first. Then, in Android Studio, go to Run > Edit Configurations... and select Show Device Chooser Dialog under Deployment Target Options.

Run your project, and select the VS Emulator, ignoring the invitation to “Turn off Hyper-V”.

RBT
  • 24,161
  • 21
  • 159
  • 240
lotosbin
  • 637
  • 9
  • 9
  • 3
    I tried using your solution. But as soon as i want to run a Android emulator with the Microsoft emulator it gives me the same(-ish) error as when i try to run the Android emulator with Android studio. ( literally complains about incompatibility with Hyper-V ). Do you have any other alternatives for this ? – Timon Apr 21 '17 at 09:07
  • https://www.visualstudio.com/zh-hans/vs/msft-android-emulator/?rr=https%3A%2F%2Fwww.google.com%2F – lotosbin Apr 21 '17 at 15:18
  • 1
    The VS android emulator is missing new API version. The bad news is, MS is not going to to publish new versions for it. Read this: https://forums.xamarin.com/discussion/comment/278669/#Comment_278669 – Junle Li Dec 24 '17 at 14:30
  • 1
    **For Android Studio developers** : Please go to the bottom of the post mentioned in the answer to download the standalone installer of Microsoft Android Emulator which can be used with Android Studio or click [this](https://aka.ms/vscomemudownload) link. – RBT Aug 07 '18 at 06:43
  • 1
    @JunleLi I'm not sure your comment is still valid (post Win10 Apr2018 update) ... I'm able to run a Pie Pixel 2 emulation via Hyper-V – George 2.0 Hope Nov 12 '18 at 09:12
11

Hyper-V added support for nested virtualization in the Windows 10 Anniversary Update (released August 2016) and Windows Server 2016. However, the only Microsoft-supported usage of nested virtualization is running Hyper-V within the VM, not HAXM. From the official documentation, "Virtualization applications other than Hyper-V are not supported in Hyper-V virtual machines, and are likely to fail."

That said, the change log for the latest release of HAXM reports that Intel "Fixed an issue with Hyper-V nested virtualization support, which had prevented Android Emulator from booting." So while it isn't supported by Microsoft, it seems running HAXM nested in a Hyper-V VM may be possible.

If that's the case, to get HAXM working in a Hyper-V VM, you will need to enable nesting for that VM. Run this command on the VM while it is in the OFF state:

Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true

After that, you should be able to install the latest version of HAXM within the VM, allowing use of the Android Emulator. Again, I haven't personally verified this, and it isn't supported by Microsoft, so your mileage may vary.

Full disclosure: I work at Microsoft on the Hyper-V team.

[Edit 7/2/2018]: Android Emulator support for Hyper-V acceleration was announced earlier this year, and is currently in preview. See the announcement post for details.

joslack
  • 302
  • 2
  • 4
  • 1
    While it technically works, it's slow as hell. And won't use GPU. So...unusable. – Miha Markic Oct 13 '17 at 07:15
  • @MihaMarkic That happens, if you are running the ARM-VM – Hunv Nov 08 '17 at 14:28
  • 1
    For me the Android SDK Manager was not willing to install HAXM. You can download and install it by yourself here: https://software.intel.com/en-us/articles/intel-hardware-accelerated-execution-manager-intel-haxm. After this I had to set the GPU Emulator Mode in the settings of the VM to "auto" and the emulator worked in the VM. – Hunv Nov 08 '17 at 14:40
  • Please do keep us updated if anything changes on this front. – Jansky Dec 11 '17 at 15:07
  • Update: Earlier this year, we announced a preview for Hyper-V acceleration support for the Android Emulator (i.e. using Hyper-V instead of HAXM). This eliminates the need to run the emulator nested in a VM. See here for details: https://blogs.msdn.microsoft.com/visualstudio/2018/05/08/hyper-v-android-emulator-support/ – joslack Jul 02 '18 at 23:13
8

Microsoft posted a link to allow Hyper-V as hardware accelerator for android emulator run in windows.

The link is here

Here is the instructions.

  1. Enter About in the Windows search box.

  2. Select About your PC in the search results.

  3. Scroll down in the About dialog to the Windows specifications section.

  4. Verify that the Version is at least 1803.

  5. Enter windows features in the Windows search box and make sure both Hyper-V and Windows Hypervisor Platform are checked.

  6. Open SDK manager in Android Studio, make sure your Android Emulator version is at least 27.2.7.

  7. Restart your computer, and relaunch your Android Emulator in AVD Manager in Android Studio.

user1455180
  • 511
  • 4
  • 9
  • Thanks! It wasn't clear to me at first that I need to enable *two distinct* windows features; I had enabled only Hyper-V. I still don't understand what the difference between the two are though. – jlh May 22 '19 at 15:19
7

Confirmed: Running Windows 10 version 1803, with Hyper-V and Windows Hypervisor platform enabled, Android Studio's Emulator works. I am using Android Studio 3.2.1 and Android Emulator 28.0.22.

3

Just make sure before you start with the steps suggested by lotosbin you complete the following:

Open an admin command prompt and enter the following; then restart the emulator.

`reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Android SDK Tools" /v Path /d %localappdata%\Android\sdk`

Or update the registry manually:

  1. In regedit, navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node.
  2. Create a new key named Android SDK Tools(if not there already).
  3. Navigate to that key.
  4. Create a new string value named Path. Set its value to the location of your Android SDK, which will be like C:\Users\YourName\AppData\Local\Android\sdk.
Scorpio_
  • 41
  • 1
  • 1
    Why? What is this for? What happens if not? – Hunv Nov 08 '17 at 14:06
  • It's actually answering another question. If you do what @lotsobin suggested https://stackoverflow.com/a/38090974/3647974 and you do not see the device showing up, you should try what is explained here. – Jason Saruulo Jun 25 '18 at 20:54
  • On my machine I already had this registry entry with `path` string pointing to `C:\Program Files (x86)\Android\android-sdk`. Do I still need to update this entry to AppData path in your post? – RBT Aug 07 '18 at 05:29
3

Microsoft has announced a better solution

Today, at Build 2018, we announced a preview of the Google Android emulator that’s compatible with Hyper-V, available on the Windows 10 April 2018 Update. This enables developers with Hyper-V enabled on their machines to use a hardware accelerated Android emulator, without needing to switch to Intel’s HAXM hypervisor. Amazing work was done by the Windows Hyper-V team, with help from the Xamarin team, to make to this happen.

heyxh
  • 571
  • 7
  • 11
1

Just to complement @lotosbin's answer and add an additional information. This information is regarding when you are trying to start your app in Microsoft's standalone Android emulator from Android Studio.

On the Select Deployment Target window there are two sections namely:

  1. Connected Devices - It shows up physical android devices attached to your computer through USB port e.g. mobile, tablet if you want to deploy your app into an actual device
  2. Available Virtual Devices - It shows up Android virtual emulators which are build from specific device definition e.g. Nexus 5X API 28

Interestingly, Microsoft's Android emulator shows up in Connected Devices section. So Android Studio treats Microsoft's Android emulator as a physical device instead even though it is a virtual emulator only. Please see the screenshot below:

enter image description here

Additionally, you can check the health and current status of Microsoft's Android emulator inside Hyper-V Manager also as shown in below screenshot:

enter image description here

RBT
  • 24,161
  • 21
  • 159
  • 240