Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Emulator is not working on Windows 11 when WSL2 is installed

Setup:

  • Windows 11 Home 21H2 22000.132
  • AMD Ryzen 5900X
  • WSL2
  • Android studio lastest build (also tried with latest beta)

Problem: As soon as I install WSL2, the emulator stops working. It's giving the following error message:

C:\Users\gusta\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Android_TV_1080p_API_300
emulator: Android emulator version 30.8.4.0 (build_id 7600983) (CL:N/A)
handleCpuAcceleration: feature check for hvf
added library vulkan-1.dll
Failed to open /qemu.conf, err: 2
C:\Users\gusta\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: WHPX: Failed to setup partition, hr=c0350005
C:\Users\gusta\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: failed to initialize WHPX: Invalid argument

Using WSL2 at the same time as the android emulator was working before on an Intel i7 4770k processor, but stopped working after a processor upgrade to a AMD Ryzen 5900x and fresh install of Windows 11.

For clarification: I'm not trying to run the emulator from WSL2, I'm trying to run it from Android Studio. When trying to start it from Android Studio it never launches, when trying to run it from the Windows Command Line I get the above error.

The "Failed to open /qemu.conf" is possible to solve by creating that file manually, as explained by this answer. That however doesn't fix the two later errors with WHPX.

I've followed the official instructions on this page (Following the AMD with Hyper-V option WHPX). I think the problem has to do with Hyper-V running which WSL2 is using if I'm not misstaken. But according to the above link it should be possible to run the emulator at the same time as Hyper-V using WHPX. I've also tried using the Android Emulator Hypervisor Driver for AMD processors, which is giving me the exact same result.

Activated Windows features:

Windows features

Thankful for any help, and please tell me if I need to add more information

like image 621
Gustav P Svensson Avatar asked Aug 18 '21 16:08

Gustav P Svensson


People also ask

Can Android Studio run on Windows 11?

The System Requirements for Android Studio on Windows Your PC must meet the following requirements to run Android Studio efficiently: 64-bit Microsoft Windows OS 8/10/11. 1280 x 800 minimum screen resolution. x86_64 CPU architecture; 2nd generation Intel Core or newer; or AMD CPU with Hypervisor support.

Why is my Android Studio emulator not working?

If the Android Emulator does not start properly, this problem is often caused by problems with HAXM. HAXM issues are often the result of conflicts with other virtualization technologies, incorrect settings, or an out-of-date HAXM driver. Try reinstalling the HAXM driver, using the steps detailed in Installing HAXM.

Does HAXM support Windows 11?

Your computer must be running Windows 11 or Windows 10 Version 1909 or later.

Does emulator emulator work with Android Studio?

Emulator started working after I installed Android Studio. The SDK is not installed with VS 2022 and it's install was 2 step, 1st install was Visual Studio, the 2nd part was to install those pieces needed to use Xamarin. I might have thought that the second part might have installed the Android SDK but it didn't.

Can't run Hyper-V on Android Studio Emulator on Windows 11?

Android Studio emulator doesn't support run Hyper-V on Windows 11, we can disable Hyper-V to run but if we do that applications which require Hyper-V to run like WSL2, Docker then fail to run.

Does the Android emulator fail to start on Windows 11?

There are at least a few dozen reports online of the Android Emulator failing to start on Windows 11 ( via Mishaal Rahman on Twitter) when using Hyper-V, Microsoft’s native hypervisor in Windows.

Does WSL2 run on Intel processors?

This problem only occurs with AMD processors, I have two systems both with WSL2 and Docker running on the latest Windows 11 (Insider Beta) build. One with an AMD Ryzen 5950 and one with an Intel i7-8086K. On the Intel system the emulator runs fine with hardware acceleration together with WSL2 and Docker.


Video Answer


3 Answers

Newer Answer

I found and tested in shorter toggle mechanism.

The configuration for Windows Feature:

  • Windows Subsystem for Linux is installed.
  • Windows Hypervisor Platform is installed.
  • Hyper-V is installed.

If you need the Emulator, you only need to turn off Hypervisor + Restart. Run: bcdedit /set hypervisorlaunchtype off

If you need the Docker back, you can run the hypervisor hence disabling Emulator. Run: bcdedit /set hypervisorlaunchtype auto

You need to restart after setting Hypervisor

You cannot run both at the same time. Another forum worth checking in How about running docker? in my older answer below.


Older Answer

I think I solved this issue, tested to run from CMD / Android Studio and ran perfectly as before installing WSL. There are several step we go:


Configuring Windows Feature:

  1. Removed Windows Subsystem for Linux
  2. Removed Windows Hypervisor Platform
  3. Removed Hyper-V

Here is my current setup:

Windows Feature


Reverting AVD setup

I know after removing there are some odds because the AVD still get the same error as before and expected to get into WSL. I stumbled and found something when ran:

C:\Users\[NAME]\AppData\Local\Android\Sdk\emulator\emulator-check.exe accel

That command will check the current accel. It explains that the Hypervisor need to be set off and give specific help: run bcdedit /set hypervisorlaunchtype off.

After running the bcdedit, I restarted and all is reverted. Now I can run emulator both from CMD and Android Studio perfectly.


How about running docker?

Sad truth, yeah you cannot run both pararel. There are several workaround in this forum:

How can I run both Docker and Android Studio Emulator on Windows?

Several option ranging from changing emulator, add & remove docker when in need using above step, created nested vm, etc. My personal choice right now is using another Emulator for the time being and removed docker for the latter.


like image 137
Andrea Lk Avatar answered Oct 26 '22 23:10

Andrea Lk


This issue is tracked by Google bug https://issuetracker.google.com/issues/202188690

like image 35
Johan Paul Avatar answered Oct 26 '22 23:10

Johan Paul


I finally got this working using this fix (answer number 48). Seems like a valid workaround until windows fixes this issue. I downloaded the compiled version for windows and moved it to my emulator path C:\Users\<username>\AppData\Local\Android\Sdk\emulator. Seems to be versions available for linux and mac as well but I haven't tested those.

like image 28
Gustav P Svensson Avatar answered Oct 26 '22 22:10

Gustav P Svensson