本文介绍了使用 Ryzen 处理器同时运行 WSL2 和 Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我的 api 运行 WSL2,并用一个 Android 模拟器来运行我的应用程序,这样我就可以测试所说的 api.当我激活 Hyper-V 时,WSL2 运行良好.然后我尝试使用 Android Studio 的模拟器,它只是挂起,从不启动模拟器.

I would like to run WSL2 with my api in it, and an Android emulator to run my app so I can test said api. 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.

现在,如果我完全停用 Hyper-V(在 Windows 功能屏幕中并通过 bcdedit/set hypervisorlaunchtype off)模拟器确实可以完美启动,但是 WSL2 现在当然不能工作了..

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...

我在这里查看了很多主题,但没有成功.例如 如何运行 Android 模拟器windows 同时使用带有 zsh 的 WSL2?在 WSL 中使用直接在 Windows 中运行的模拟器运行 React Native本教程一个>.目前没有成功.

I took a look at lots of the topics around here without success. For example How to run Android emulator on windows while using WSL2 with zsh?, Running React Native in WSL with the emulator running directly in Windows or this tutorial. No success so far.

如前所述,我正在使用 Ryzen 处理器.

As said I'm using a Ryzen processor.

推荐答案

我找到了解决办法.我正在运行 Windows 11 Pro,更新 21H2,操作系统版本 22000.51AMD.

I was able to find way around it. I'm running Windows 11 Pro, Update 21H2, OS build 22000.51, AMD.

这里是 Google 文档如何设置模拟器AMD 处理器.它需要禁用 Hyper-V 和 WHPX.这与运行 WSL2 不匹配.

Here is Google documentation how to setup emulator for AMD processors. It requires Hyper-V and WHPX to be disabled. And that does not go in pair with running WSL2.

我的设置是:

  • 在 Windows 下运行的 Android Studio 和 IntelliJ
  • 在 Ubuntu (WSL2) 下运行的 Docker、DB 和其他服务

我做了什么:

  1. 启用 Hyper-V 和 WHPX.
  2. 在 Hyper-V 管理器中添加了新的 Android VM 那样
  3. 找到 Android VM IP 地址(我通过运行 Android wi-fi 选项来做到这一点)并使用 adb connect <ip going here>:5555
  4. 如果连接正确,它应该会出现在 Android Studio 中.

我尝试从 Ubuntu adb connect 到 Android,但它不能开箱即用.应该可以使用一些 WSL2 >主机重定向,但我目前不需要它,也没有进一步研究.

I tried to adb connect to the Android from Ubuntu, but it does not work out of the box. Should be doable with some WSL2 > Host redirects, but I currently do not need it and did not research it any further.

最后困扰我的是默认的 Android VM 分辨率(看起来像水平方向的平板电脑).可以像这样调整它.

Last thing that bugged me was default Android VM resolution (looks like tablet in horizontal orientation). It is possible to adjust it like that.

我们可能需要等待 Google 推出使用与 WSL2 相同的仿真类型的模拟器.

We probably need to wait for Google to come up with emulator that uses the same emulation type as WSL2.

不起作用/丢失的东西(或者我不知道该怎么做):

Things that do not work/are missing (or I do not know how to do it):

  • 无法即时更改屏幕方向
  • 键入时未显示软件键盘(当您需要使用它测试 UI 时出现问题)
  • Hyper-V 中没有 GPU 加速(Microsoft 由于安全原因禁用了它(?),但似乎有一种方法可以启用它,没有尝试过,因为我的需要默认性能很好)

这篇关于使用 Ryzen 处理器同时运行 WSL2 和 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 01:20