Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running WSL2 and Android Studio at the same time with a Ryzen processor

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.

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

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.

As said I'm using a Ryzen processor.

like image 951
Jeremy Belolo Avatar asked Jun 09 '21 22:06

Jeremy Belolo


1 Answers

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

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.

My setup is:

  • Android Studio and IntelliJ running under Windows
  • Docker, DBs and other services running under Ubuntu (WSL2)

What I did:

  1. Enable Hyper-V and WHPX.
  2. Added new Android VM in Hyper-V Manager like that
  3. Find Android VM IP address (I did so by going to running Android wi-fi options) and use adb connect <ip goes here>:5555
  4. If connected properly, it should appear in Android Studio.

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.

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

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):

  • cannot change screen orientation on the fly
  • software keyboard is not showing up when typing (problem when you need to test your UI with it)
  • no GPU acceleration in Hyper-V (Microsoft disabled it due to secuirty reasons (?) but there seems to be a way to enable it, have not tried it, for my needs default performance is fine)
like image 127
otocon Avatar answered Sep 24 '22 02:09

otocon