microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.34k stars 815 forks source link

Android emulator not starting anymore #6471

Closed ad-on-is closed 3 years ago

ad-on-is commented 3 years ago

Windows 10 21296 AMD 4800H

I don't know whether this is related to WSL, Windows or Android emulator itself, but here's what's happening.

I used to run WSL2, Docker (WSL2) and Android Studio emulator side-by-side. Everything worked. Docker was up and running in WSL2. I could launch emulators from within Android Studio.

Now, the emulators stopped working. AVD Manager throws a The emulator process for AVD Pixel_4_API_30 was killed. error, without further information.

When I try to run it manually via the console, I get these errors:

.\emulator -avd Pixel_4_API_30

WHPX: Failed to get virtual processor registers, hr=c0350005
WHPX: Failed to emulate PortIO access with EmulatorReturnStatus: 64
WHPX: Failed to exec a virtual processor
ahmedalnuaimi commented 3 years ago

Neither on Windows itself nor on WSL. It has been like this for about two weeks.

viet-quocnguyen commented 3 years ago

I have the same problem!

dbanda commented 3 years ago

Same problem. it was broken by windows update 21292.1000

https://developercommunity.visualstudio.com/content/problem/1310877/unable-to-start-android-emulator.html

Windows 21301.1000

viet-quocnguyen commented 3 years ago

Hey guys, I think the workaround is to turn off HyperV when Windows startup, maybe there is a conflict between HyperV and HAXM (I thought this problem is already resolved in the latest version of Android Studio?)

To do this, open Powershell as Admin -> bcdedit /set hypervisorlaunchtype off -> restart pc. By doing this, you will not be able to run wsl2 but android emulator will work. To turn HyperV back on, open Powershell as Admin -> bcdedit /set hypervisorlaunchtype auto -> restart pc.

Hopefully, there will be a solution for this problem since it's pretty inconvenient to switch back and forth just to get the emulator working.

ad-on-is commented 3 years ago

@viet-quocnguyen This is not a workaround, since some folks (like me) rely on simultaneously running WSL2 and emulators. I.e. how else would you test a NodeJS API (running in WSL2) on a Flutter app, running in an Android TV emulator?

viet-quocnguyen commented 3 years ago

@viet-quocnguyen This is not a workaround, since some folks (like me) rely on simultaneously running WSL2 and emulators. I.e. how else would you test a NodeJS API (running in WSL2) on a Flutter app, running in an Android TV emulator?

@ad-on-is I see... It will be a pain but maybe you could try to run the APIs on windows instead? Just a temporary set up so you could get work done I guess.

ad-on-is commented 3 years ago

@viet-quocnguyen Sure, there are multiple temporary solutions, like switching to VirtualBox.

ad-on-is commented 3 years ago

Is there any official statement regarding this issue?

benhillis commented 3 years ago

Thanks for reporting the issue, we have routed the report to the correct team and they are investigating a fix.

alexeagleson commented 3 years ago

Wondering has there been any update on this? It's a pretty big blocker for me. I'm unable to disable Hyper-V since I rely on WSL2 for the development work that the emulator is using.

Thanks!

WSLUser commented 3 years ago

@all WSL2 has it's own feature known as VMM (Virtual Machine Management) that is required to be added in addition to the WSL feature for WSL2 to run. It is based on Hyper-V but does NOT require the Hyper-V feature to be enabled to run. The only reason to also enable Hyper-V is if you still wish to run VMs in Hyper-V or to use it's commandline functionalities to "hack" WSL2 for stuff like virtual NICs as workarounds. Has anyone actually tested the emulator not working with only WSL2 enabled and NOT Hyper-V? I think it's still likely to be broken but there's a small chance it can still work until proven otherwise.

ad-on-is commented 3 years ago

Wondering has there been any update on this? It's a pretty big blocker for me. I'm unable to disable Hyper-V since I rely on WSL2 for the development work that the emulator is using.

Thanks!

I think this issue is extremely low prioritized, since the percentage of users who run WSL2 and Android emulators simultanously is very low.

ad-on-is commented 3 years ago

@ALL WSL2 has it's own feature known as VMM (Virtual Machine Management) that is required to be added in addition to the WSL feature for WSL2 to run. It is based on Hyper-V but does NOT require the Hyper-V feature to be enabled to run. The only reason to also enable Hyper-V is if you still wish to run VMs in Hyper-V or to use it's commandline functionalities to "hack" WSL2 for stuff like virtual NICs as workarounds. Has anyone actually tested the emulator not working with only WSL2 enabled and NOT Hyper-V? I think it's still likely to be broken but there's a small chance it can still work until proven otherwise.

I tested all possible options of enabling/disabling Windows Features and it comes down to either have a working emulator, or a working WSL2/Docker, but not both. Maybe I still may have missed something, and someone can point to a workaround.

alexeagleson commented 3 years ago

Wondering has there been any update on this? It's a pretty big blocker for me. I'm unable to disable Hyper-V since I rely on WSL2 for the development work that the emulator is using. Thanks!

I think this issue is extremely low prioritized, since the percentage of users who run WSL2 and Android emulators simultanously is very low.

Likely. If it were a new feature request that would be one thing, but I'm hoping that because it's something that USED to work a few weeks ago and has since been broken with an update, that's it's something that be corrected without too much headache.

ad-on-is commented 3 years ago

Likely. If it were a new feature request that would be one thing, but I'm hoping that because it's something that USED to work a few weeks ago and has since been broken with an update, that's it's something that be corrected without too much headache.

Definitely! It used to work before Windows 21292 (iirc).

murbanowicz commented 3 years ago

I have same issue.

Ryzen 3900X Windows Insiders 21322.

manoj398 commented 3 years ago

Same issue. Windows Insiders 21318

MZO9400 commented 3 years ago

Same issue, 21322 Dev

patfla commented 3 years ago

I wonder if backing up from Dev to Beta will give me a version where the emulator will work again? It'd be helpful if the "Pick your Insider settings" screen would dynamically tell you just what version each corresponds to.

patfla commented 3 years ago

This page does give versions for Dev, Beta, and Release Preview at the bottom:

https://insider.windows.com/en-us/

SmartPolarBear commented 3 years ago

Is there any fix in the latest Dev Channel Build 21327 ?

I have tested on my laptop (HP OMEN15, i7-10870H, RTX2060) that the build 21327 fixed the problem .

ad-on-is commented 3 years ago

Can confirm, Windows 21327 fixes the issue.

manoj398 commented 3 years ago

Can confirm, Windows 21327 fixes the issue.

Can confirm

zachary-russell commented 3 years ago

I can also confirm that this fixes the issue for me.

patfla commented 3 years ago

I'd be very curious to know just what changed to fix things.

dominicm00 commented 3 years ago

21327 fixed the issue for me on AMD/Nvidia platform

viet-quocnguyen commented 3 years ago

21327 fixed the issue. Thanks guys!

patfla commented 3 years ago

I'm back to this again. The emulator is working - but it's very slow. Android Studio told me:


Detected ADB

The ADB binary found at D:\AndroidSDK\platform-tools\adb.exe is obsolete and has seriousperformance problems with the Android Emulator. Please update to a newer version to get significantly faster app/file transfer.

OK

Upgraded Android SDK Platform-Tools (and other out-of-date SDK Tools).

However Haxm won't install - the prereqs aren't met and I believe this has to do with Hyper-V being turned on. I don't believe I'm supposed to have Hyper-V on Win10 Home but this is what I see in services.msc:

https://imgur.com/a/qkYZqYP

tirthankarkundu17 commented 3 years ago

@ad-on-is Hey, is this working ? I am facing the same challenge here. Both WSL2 and Emulator doesn't work properly. I use Windows 10 Home 20H2 OS Build : 19042.928. Currently emulator starts but it's so so slow that nothing can be done with it. Any help or insights would be appreciated.

ad-on-is commented 3 years ago

@tirthankarkundu17 Sorry, but you're not facing the same challenge, since your emulator spins up. This issue is about the emulator not running at all, while having WSL enabled.

I don't know what could be wrong with your setup. Your best bet, is to either research a bit deeper, like whether it's really WSL-related or not, or to open up a new and more detailed issue.

JerryBels commented 3 years ago

I have a related issue. WSL2 is working perfectly when I'm having Hyper-V activated. Then I'm trying to use Android Studio's emulator and it just hangs, never launching the emulator. Now, if I deactivate Hyper-V entirely (in the windows features screen and through bcdedit /set hypervisorlaunchtype off) the emulator does launch perfectly, but of course WSL2 won't work now...

So, if I want to dev my api on WSL2 and run my app on an android emulator, I can't?

I have a Ryzen 5 processor.

stevenlafl commented 3 years ago

I have a related issue. WSL2 is working perfectly when I'm having Hyper-V activated. Then I'm trying to use Android Studio's emulator and it just hangs, never launching the emulator. Now, if I deactivate Hyper-V entirely (in the windows features screen and through bcdedit /set hypervisorlaunchtype off) the emulator does launch perfectly, but of course WSL2 won't work now...

So, if I want to dev my api on WSL2 and run my app on an android emulator, I can't?

I have a Ryzen 5 processor.

Same problem. Brand new install. This time, what I did was.. I installed Docker, works fine and runs. Installed Android Studio, works fine and runs. I can run both together fine. However, when I installed Debian (which uses WSL 2) now all of a sudden I can't get the emulator to run.

Edit: I just figured this out. And it's really annoying.

You must have the Android Emulator running on your MAIN monitor

After I did this, it works every time. Here it is running Android Studio, VirtualBox, Debian WSL-2, and Docker all at once. Once you get it to load, you can move it to other monitors by following the answer here: https://stackoverflow.com/questions/44708452/avd-crash-on-second-monitor

image

AnQueth commented 3 years ago

same problem, wsl2 is fine, emulator will not start .

otocon commented 3 years ago

I found a temporary workaround by running Android Emulator with Hyper-V Manager. Description here.

EDIT That's the error I get when trying to run emulator in the old way on AMD machine and having WSL2 running as well: emulator.exe -avd Pixel_3a_API_30 emulator: Android emulator version 30.7.5.0 (build_id 7491168) (CL:N/A) handleCpuAcceleration: feature check for hvf added library vulkan-1.dll C:\Users\lukas\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: WHPX: Failed to setup partition, hr=c0350005 C:\Users\lukas\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: failed to initialize WHPX: Invalid argument

Zeswen commented 3 years ago

Same error as @otocon, WHPX is not working for AVD in Windows 11, please reconsider opening the issue.

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

There are two possible workarounds:

Disable Hyper-V (Keep in mind WSL2 or any VM won't work without this)

To disable Hyper-V you must follow these steps:

  1. Open Turn Windows features on or off.
  2. Uncheck Hyper-V and Windows Hypervisor platform (it may be required to uncheck Windows Sandbox).
  3. Open Android Studio and SDK Manager.
  4. In SDK tools, install Android Emulator Hypervisor Driver for AMD Processors (installer).

Open the emulator with no acceleration

  1. Open a terminal.
  2. Enter cd C:\Users\User\AppData\Local\Android\Sdk\emulator\ with your user.
  3. Enter .\emulator.exe -avd Pixel_4a_API_30 -accel off with your AVD device name.
Nouradawy commented 3 years ago

I have a related issue. WSL2 is working perfectly when I'm having Hyper-V activated. Then I'm trying to use Android Studio's emulator and it just hangs, never launching the emulator. Now, if I deactivate Hyper-V entirely (in the windows features screen and through bcdedit /set hypervisorlaunchtype off) the emulator does launch perfectly, but of course WSL2 won't work now... So, if I want to dev my api on WSL2 and run my app on an android emulator, I can't? I have a Ryzen 5 processor.

Same problem. Brand new install. This time, what I did was.. I installed Docker, works fine and runs. Installed Android Studio, works fine and runs. I can run both together fine. However, when I installed Debian (which uses WSL 2) now all of a sudden I can't get the emulator to run.

Edit: I just figured this out. And it's really annoying.

You must have the Android Emulator running on your MAIN monitor

After I did this, it works every time. Here it is running Android Studio, VirtualBox, Debian WSL-2, and Docker all at once. Once you get it to load, you can move it to other monitors by following the answer here: https://stackoverflow.com/questions/44708452/avd-crash-on-second-monitor

image

you are a legend this really fixed the issue don't run the emulator on your second screen, only your main monitor.

JerryBels commented 3 years ago

Doesn't help for me.

JerryBels commented 3 years ago

Same error as @otocon, WHPX is not working for AVD in Windows 11, please reconsider opening the issue.

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

There are two possible workarounds:

Disable Hyper-V (Keep in mind WSL2 or any VM won't work without this)

To disable Hyper-V you must follow these steps:

  1. Open Turn Windows features on or off.
  2. Uncheck Hyper-V and Windows Hypervisor platform (it may be required to uncheck Windows Sandbox).
  3. Open Android Studio and SDK Manager.
  4. In SDK tools, install Android Emulator Hypervisor Driver for AMD Processors (installer).

Open the emulator with no acceleration

  1. Open a terminal.
  2. Enter cd C:\Users\User\AppData\Local\Android\Sdk\emulator\ with your user.
  3. Enter .\emulator.exe -avd Pixel_4a_API_30 -accel off with your AVD device name.

I thought this could do it for me too, but it's so damn slow it's not even usable on my machine - I mean, 20 minutes to launch, 30 seconds to register a click... No can do. The "main monitor" stuff just feels weird to me and of course doesn't help at all in my case.

Which makes me wonder. Are we better off letting go of WSL2 and try to run our API in a Virtualbox or similar? Since it's visibly a very low priority bug... Even lower for Ryzen users like me...

Jictyvoo commented 3 years ago

I'm looking for a fix for this too, I'm using Windows 11 Pro - 21H2 22000.194 and AVD doesn't work with Virtual Machine Platform enabled, but if I disable AVD works and WSL 2 don't.

I'm think that's valid to reopen the issue

jmSfernandes commented 3 years ago

Im facing the same issue, Windows 11 Home 21H2 22000.258. My Emulator was working just fine prior to updating to windows 11. Please reopen the issue.

flipswitchingmonkey commented 3 years ago

There is a workaround, kind of, until this is (hopefully soon, but seeing how there are all kinds of problems with Ryzen (scheduler...) I'm not holding my breath...) fixed.

I got the emulator working at good speed (and reasonably stable, so far) by installing Android Studio inside WSL2, and by installing the vGPU drivers for WSLg, AND by updating the Mesa drivers to the latest version. Like so:

wslg

see https://github.com/microsoft/wslg in Powershell:

wsl --update

in WSL shell

sudo apt update
sudo apt upgrade

Install vGPU graphics drivers (see links on wslg page)

Install latest Mesa drivers

see https://itsfoss.com/install-mesa-ubuntu/

sudo add-apt-repository ppa:kisak/kisak-mesa
sudo apt update
sudo apt upgrade

Install Android Studio

sudo apt install openjdk-11-jdk
sudo add-apt-repository ppa:maarten-fonville/android-studio
sudo apt install android-studio

I'm using fish so some paths may not be set:

fish_add_path ~/Android/Sdk/platform-tools/
fish_add_path ~/Android/Sdk/emulator/

also add

set -x ANDROID_SDK_ROOT "/home/myuser/Android/Sdk"

to your ~/.config/fish/config.fish

Obviously this may vary slightly for bash etc.

You probably also need to fiddle with the /dev/kvm permissions since they default to root only.

It also means that you have to do your coding inside WSL.

alokraj68 commented 2 years ago

This bug needs to be reopened. can confirm there is no way to run an emulator with any of the above in Windows 11 with hyper v. By turning off Hyper v, version 29 Emulator is running.

aajahid commented 2 years ago

Damn it! Wasted two days on this! Now I have to downgrade to window 10 and setup whole thing once again :(

DanielCarmingham commented 2 years ago

I've tracked this problem down to an issue with the Android Emulator WHPX (Windows Hypervisor Platform) support. (Or a breaking change in the WHPX APIs in Windows 11)

It does not appear to be related to WSL other than that by enabling WSL you would also need to enable WHPX to have hardware acceleration of the Android Emulator.

I've built the Android Emulator from source with some very small changes to the WHPX integration and in my (admittedly very basic) testing, it appears to function correctly.

For what it's worth, I am on an Intel i7-1185g7 CPU and it worked fine prior to the Windows 11 upgrade.

alokraj68 commented 2 years ago

I am getting this issue in AMD Ryzen 7. Also, this issue is more there only in AMD chipset and not in windows. I am using an i7 7700HQ and it works flawlessly there.

HazyFish commented 2 years ago

Reproduced on i7-1165G7 with a clean install of Android Studio on Windows 11 (22000.258).

Hkmu commented 2 years ago

Facing the same issue. Tried almost all ways I can find to make AVD and WSL2 work at the same time. In the end, it turned out to be totaly a futile attempt. Reopen this issue please.

System info:

hanskokx commented 2 years ago

Having the same issue here.

Here's a link to the Google issue tracking this: https://issuetracker.google.com/issues/202188690?pli=1

RikkaW commented 2 years ago

I found a solution from the Google issue tracker to make AVD work with Hyper-V enabled on my AMD CPU. https://issuetracker.google.com/issues/202188690#comment18

image

This requires compiling qemu, but I didn't encounter problems while following the guide.

Binary files compiled by me: https://paste.c-net.org/BlatantEnjoying (a random site that can upload files, the word in the URL is meaningless). Extract to <ANDROID_SDK>/emulator/qemu/windows-x86_64.

LefanTan commented 2 years ago

I found a solution from the Google issue tracker to make AVD work with Hyper-V enabled on my AMD CPU. https://issuetracker.google.com/issues/202188690#comment18

image

This requires compiling qemu, but I didn't encounter problems while following the guide.

Binary files compiled by me: https://paste.c-net.org/BlatantEnjoying. Extract to <ANDROID_SDK>/emulator/qemu/windows-x86_64.

You actually made it work! I copied the binary files to <ANDROID_SDK>/emulator/qemu/windows-x86_64, and my emulator launched successfully with Docker running. What changes did you make to the binary files if I may ask?

Thanks btw.