简体   繁体   English

Android Studio 模拟器无法使用 WHPX 在 Windows 11 上运行

[英]Android Studio Emulator is not working on Windows 11 using WHPX

I have Windows 11 on my system.我的系统上有 Windows 11。
The system specifiction:系统规格:

  • Edition: Windows 11 Home Single Language版号:Windows 11家单语
  • Update: 21H2更新:21H2
  • Installed on: 06-07-2021安装时间:06-07-2021
  • OS build: 22000.65操作系统版本:22000.65
  • Experience: Windows Feature Experience Pack 421.17400.45.3体验:Windows 功能体验包421.17400.45.3

I have fresh installed Android Studio.我已经全新安装了 Android Studio。 Now I want to run the emulator without Intel HAXM as I want to run it alongside wsl2.现在我想在没有 Intel HAXM 的情况下运行模拟器,因为我想将它与 wsl2 一起运行。

So in my optional feature, these two features are enabled所以在我的可选功能中,启用了这两个功能

  1. Windows HyperVisor Platform Windows HyperVisor 平台
  2. Virtual Machine Platform虚拟机平台

But while running the emulator I'm getting this error:但是在运行模拟器时出现此错误:

❯ .\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....\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: WHPX: Failed to setup partition, hr=c0350005
C:\Users....\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe: failed to initialize WHPX: Invalid argument

Anyone got suggestions, how to resolve this issue.任何人都有建议,如何解决这个问题。

WHPX as of now is not working with Windows 11, I will update this answer when it gets fixed.截至目前,WHPX 不适用于 Windows 11,我将在修复后更新此答案。

There are two possible workarounds:有两种可能的解决方法:

Disable Hyper-V (Keep in mind WSL2 or any VM won't work without this)禁用 Hyper-V(请记住 WSL2 或任何 VM 没有这个都将无法工作)

To disable Hyper-V you must follow these steps:要禁用 Hyper-V,您必须执行以下步骤:

  1. Open Turn Windows features on or off .打开Turn Windows features on or off
  2. Uncheck Hyper-V and Windows Hypervisor platform (it may be required to uncheck Windows Sandbox ).取消选中Hyper-VWindows Hypervisor platform (可能需要取消选中Windows Sandbox )。
  3. Open Android Studio and SDK Manager.打开 Android Studio 和 SDK 管理器。
  4. In SDK tools, install Android Emulator Hypervisor Driver for AMD Processors (installer) .在 SDK 工具中,安装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.与您的用户一起输入cd C:\\Users\\User\\AppData\\Local\\Android\\Sdk\\emulator\\
  3. Enter .\\emulator.exe -avd Pixel_4a_API_30 -accel off with your AVD device name.输入.\\emulator.exe -avd Pixel_4a_API_30 -accel off和您的 AVD 设备名称。

You must disable "Virtual Machine Platform" too, not just Hyper-V您还必须禁用“虚拟机平台”,而不仅仅是 Hyper-V 在此处输入图片说明

weird for me.对我来说很奇怪。 two windows machines.两台窗户机。 both with fresh clean iso install of latest windows 11 builds (tried both dev and beta channels on both machines).两者都安装了最新的 Windows 11 版本(在两台机器上都尝试了 dev 和 beta 频道)。

the i9-9900KF desktop will run android emulator using whpx acceleration, the XPS13 i7-1185G7 fails i9-9900KF 桌面将使用 whpx 加速运行 android 模拟器,XPS13 i7-1185G7 失败

re-installed windows 10 on the XPS13 and as expected the acceleration works....在 XPS13 上重新安装了 Windows 10,并且正如预期的那样加速工作......

i give up我放弃

It's possible to run the emulator from the WSL2 side and it's what I ended up doing.可以从 WSL2 端运行模拟器,这就是我最终要做的。 You can install the GUI version of Android Studio in WSL2 and from there create the emulator as usual.您可以在 WSL2 中安装 Android Studio 的 GUI 版本,然后照常创建模拟器。

How to run GUI apps in WSL2 if it's not working already:https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps如果 WSL2 尚未运行,如何在 WSL2 中运行 GUI 应用程序:https ://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

Not an answer to the original problem but a workaround for the time being.不是原始问题的答案,而是暂时的解决方法。

这在谷歌被跟踪为问题https://issuetracker.google.com/issues/202188690

This works for me with an intel I7 11gen processor on latest version of windows 11 pro, Open Turn Windows features on or off Uncheck Hyper-V , Virtual Machine Platform , Windows Hypervisor Platform , Windows Sandbox and close Memory integrity (switch from on to off) from the Windows security Core isolation feature, after that you have to restart your device and install new AVD in your android studio and it will work fine.这对我来说适用于最新版本的 windows 11 pro 上的英特尔 I7 11gen 处理器,打开Turn Windows features on or off取消选中Hyper-VVirtual Machine PlatformWindows Hypervisor PlatformWindows Sandbox并关闭Memory integrity (从打开切换到关闭) ) 来自 Windows 安全核心隔离功能,之后您必须重新启动设备并在您的 android studio 中安装新的 AVD,它会正常工作。

Proof证明

I have been looking for a solution for a long time, because my Surface Pro 8 came with Windows 11 and I didn't wanted to switch back to Windows 10. But at the moment there seems to be no really good solution, which made me switch back to Windows 10 for now.我一直在寻找解决方案,因为我的 Surface Pro 8 是 Windows 11 的,我不想切换回 Windows 10。但目前似乎没有真正好的解决方案,这让我暂时切换回 Windows 10。 Here everything works again.这里一切正常。 :) :)

Current solution until Google releases a new version of the emulator:在 Google 发布新版本模拟器之前的当前解决方案:

Download the binaries from https://issuetracker.google.com/issues/202188690#comment27 and extract them into your emulator directory, replacing the qemu binaries.https://issuetracker.google.com/issues/202188690#comment27下载二进制文件并将它们解压缩到您的模拟器目录中,替换 qemu 二进制文件。

The latest version of Android Emulator - 31.1.2 is fixing the issue.最新版本的 Android Emulator - 31.1.2 正在修复该问题。 Update through SDK Manager.通过 SDK 管理器更新。 Released 11/11/2021. 2021 年 11 月 11 日发布。

There is a fix for this issue see:此问题有一个修复程序,请参阅:

https://issuetracker.google.com/issues/202188690#comment45

Can I get more details on how you ran the emulator on wsl2 when I ran it the window came up but nothing was displayed.当我运行 wsl2 时,我可以获取有关如何在 wsl2 上运行模拟器的更多详细信息,但窗口出现但未显示任何内容。 I am able to run nautilus and android studio on wsl2 without issue.我能够在 wsl2 上运行 nautilus 和 android studio 没有问题。 I need to be able to run with hyper-v enabled我需要能够在启用 hyper-v 的情况下运行

I can confirm this solved my issues with the emulator and Windows 11. Thanks for the work and effort to help identify my issues.我可以确认这解决了我在模拟器和 Windows 11 上的问题。感谢您帮助确定我的问题的工作和努力。 The community is very strong and collaborative.社区非常强大和协作。

In the windows 11 Version 22H2 OS Build 22581.200: Goto Windows Security --> Device Security --> Core Isolation --> Memory Integrity (Turn this to Off)在 windows 11 Version 22H2 OS Build 22581.200 中:转到 Windows Security --> Device Security --> Core Isolation --> Memory Integrity(将其关闭)

I have a AMD Ryzen 9 CPU and upgraded to Windows 11 Pro.我有一个 AMD Ryzen 9 CPU 并升级到 Windows 11 Pro。 I've tried enabling and disabling both windows features (Hyper-V and Windows Hypervisor Platform).我试过启用和禁用这两个 Windows 功能(Hyper-V 和 Windows 管理程序平台)。 Android emulator just crashes (not responding). Android 模拟器只是崩溃(没有响应)。 Also tried with and without the AMD driver.也尝试过使用和不使用 AMD 驱动程序。

System info CMD shows - Hyper-V Requirements: A hypervisor has been detected.系统信息 CMD 显示 - Hyper-V 要求:已检测到管理程序。 Features required for Hyper-V will not be displayed. Hyper-V 所需的功能将不会显示。

Any ideas?有任何想法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM