安装 WSL2 后,Android Studio 模拟器无法在 Windows 11 上运行 [英] Android Studio Emulator is not working on Windows 11 when WSL2 is installed

查看:584
本文介绍了安装 WSL2 后,Android Studio 模拟器无法在 Windows 11 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置:

  • Windows 11 家庭版 21H2 22000.132
  • AMD 锐龙 5900X
  • WSL2
  • Android studio 最新版本(也尝试过最新测试版)

问题:我一安装 WSL2,模拟器就停止工作.它给出了以下错误消息:

C:\Users\gusta\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Android_TV_1080p_API_300模拟器:Android 模拟器版本 30.8.4.0 (build_id 7600983) (CL:N/A)handleCpuAcceleration:hvf 的功能检查添加了库 vulkan-1.dll无法打开/qemu.conf,错误:2C:\Users\gusta\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe:WHPX:设置分区失败,hr=c0350005C:\Users\gusta\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe:无法初始化 WHPX:无效参数

在 Android 模拟器之前在 Intel i7 4770k 处理器上运行的同时使用 WSL2,但在处理器升级到 AMD Ryzen 5900x 并全新安装 Windows 11 后停止工作.

澄清一下:我不是要从 WSL2 运行模拟器,而是要从 Android Studio 运行它.尝试从 Android Studio 启动它时它永远不会启动,当尝试从 Windows 命令行运行它时,我收到上述错误.

无法打开/qemu.conf"可以通过手动创建该文件来解决,如

感谢您的帮助,如果我需要添加更多信息,请告诉我

解决方案

Newer Answer

我发现并测试了较短的切换机制.

Windows Feature 的配置:

  • 适用于 Linux 的 Windows 子系统 已安装.
  • Windows Hypervisor Platform 已安装.
  • Hyper-V 已安装.

如果需要模拟器,只需要关闭Hypervisor + Restart即可.运行:bcdedit/set hypervisorlaunchtype off

如果您需要返回 Docker,您可以运行管理程序从而禁用模拟器.运行:bcdedit/set hypervisorlaunchtype auto

设置Hypervisor后需要重启

您不能同时运行两者.另一个值得查看的论坛 How about running docker? 在我下面的旧答案中.


旧答案

我想我解决了这个问题,经过测试可以从 CMD/Android Studio 运行,并且像安装 WSL 之前一样完美运行.我们有几个步骤:


配置 Windows 功能:

  1. 删除了 Windows 子系统 Linux
  2. 删除了Windows Hypervisor Platform
  3. 删除了Hyper-V

这是我当前的设置:


恢复 AVD 设置

我知道删除后有一些可能性,因为 AVD 仍然出现与以前相同的错误,并且预计会进入 WSL.我在跑步时绊倒并发现了一些东西:

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

该命令将检查当前的加速度.它解释了需要启动Hypervisor并给出具体帮助:运行 bcdedit/set hypervisorlaunchtype off.

运行 bcdedit 后,我​​重新启动,一切都恢复了.现在我可以完美地从 CMD 和 Android Studio 运行模拟器.


运行 docker 怎么样?

可悲的事实,是的,您不能同时运行两者.本论坛有几种解决方法:

我该怎么办在 Windows 上同时运行 Docker 和 Android Studio 模拟器?

几个选项,包括更改模拟器、添加 &在需要时使用上述步骤删除 docker,创建嵌套 vm 等.我个人现在的选择是暂时使用另一个模拟器,并为后者删除 docker.


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:

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

解决方案

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:


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.


这篇关于安装 WSL2 后,Android Studio 模拟器无法在 Windows 11 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆