Expo AVD (Android Virtual Device) on Windows Subsystem for Linux (WSL2)
Tags: expo, reactnative, mobile, javascript
Published: 2024-03-05 19:47:10

> This article is the second and final part of two parts tutorial to completely run a _Expo_ project through _WSL2_.

**Prerequisites:**
WinRAR/7Zip
Unzip
[The previous step of this article](https://dev.to/alecell/expo-qr-code-on-windows-subsystem-for-linux-wsl2-1bjf)

----

On the [previous part of this tutorial](https://dev.to/alecell/expo-qr-code-on-windows-subsystem-for-linux-wsl2-1bjf) we managed to open our _Expo_ app by the _QR code_ adding some network configs on our _Windows_ and _WSL_. Now we'll move further to make it work with _AVD_ as well!

----

To be able to run our virtual device we'll need to have a virtual device on our _Windows_, add the _Android SDK_ on our _WSL_ and install _ADB_ to allow the connection between our _Expo_ app on _WSL_ and the virtual device on _Windows_.

### Installing _WSA_

There's a _Android_ version of _WSL_, in this case _WSA_, _Windows Subsystem Android_, it works almost like _WSL_, but its a _Android_ environment.

Testing locally on my computer and on other teammates computers it worked better, some teammates have very old computers and that was a decisive point to opt on _WSA_. So basically we'll move on with _WSA_ because it is more performant _AVD_ than _Android Studio_.

To install _WSA_ go to this [github repository](https://github.com/MustardChef/WSABuilds) scroll to the readme and, on the _Download_ section select the stable build for your _Windows_ version and processor architecture.

On the page it opened go all the way to the bottom to the download table and select the second download option, right now, while I'm writing this article, the version is `WSA_2311.40000.5.0_x64_Release-Nightly-MindTheGapps-13.0.7z`

![highlighted version to download](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n8rpws49mh6z9kfcvmri.png)

With that downloaded file move it to the root of your `C:` of your _Windows_ and extract that file there, after this you should have this folder on your `C:`

![WSA on C: folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tyxzwzrrsuqqeoyzm6ii.png)

> **Note**: if you're not able to extract that file you'll need to install `WinRAR` or `7Zip` on your _Windows_

Now open that folder and look for the script `Install.ps1` (if your _Windows_ is not configured to see the file extensions it'll be just `Install`).

![Install script on WSA folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/digq0qwsxqzy60njn656.png)

Now _right click_ on the `Install.ps1` file and click on `Run with Power Shell` or anything similar to that.

It'll open a _Power Shell_ window with a bunch of other windows and ask some permissions, but no worry, that's expected. Just click on `continue` buttons, let the windows load its views and move on. When the _Power Shell_ process finishes just press any button to close the window.

After the process finished look for a window called _Windows Subsystem Android_, it'll open with a title at the top left corner as `System`. The window is similar to this one

![WSA config window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d9hy496cc23zj75fd7qp.png)

On this window go to `Advanced Configuration` and turn the _Developer Mode_ on (that menu option could be hide on a hamburger menu at top left corner). It could ask for some admin permissions, just allow them. 

If work as expected it'll suggest you that you can run the _ADB_ server on `127.0.0.1:58526`. After turn it on you can close all the _WSA_ windows since it runs on background.

![highlighted developer mode triggered on in WSA window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6v0ohx1ivbvy0kn2lek6.png)

After close all the windows you can check if _ADB_ is working checking the _Windows_ _Task Manager_ and check if the _WSA_ is there 

![task manager showing that WSA is running as a background proccess](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xoxhce6r42n3vbxy350p.png)
_Search for Android_

#### Troubleshoot

**Running the Install.ps1**
If you get a error trying to run the `Install.ps1` script try run the `Run.bat` script instead.

**Developer mode not showing the `127.0.0.1:58526`**
If you can't see the `127.0.0.1:58526` after turn your Developer Mode on, try reinstall _WSA_ with a _PRE-RELEASE_ build instead.

### Installing _Android SDK_ on _WSL_

With your _WSA_ installed now you'll need to install _Android SDK_ on your _WSL_. _Expo_ needs that to run the app with _Android_. 

I found a [awesome tutorial](https://gist.github.com/steveclarke/d988d89e8cdf51a8a5766d69ecb07e7b) to do that on _WSL_, but we'll not use everything there and also I needed to update some of the commands so, I just get and update what is needed here.

Now open your _WSL_, go to the your user root folder and run the following commands **individually**

```bash
sudo apt install openjdk-8-jdk-headless

wget https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
mkdir -p Android/sdk
unzip commandlinetools-linux-6200805_latest.zip -d Android/sdk

export ANDROID_HOME=$HOME/Android/sdk
export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"

sdkmanager --sdk_root=${ANDROID_HOME} "tools"

sdkmanager --update
sdkmanager --list
sdkmanager "build-tools;28.0.3" "platform-tools" "platforms;android-28" "tools"
sdkmanager --licenses
```

Agree to all the agreements and, after all, you'll have a `Android` folder on your user root

![demonstration that the Android folder is there on the user root on WSL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlfn81kx9l0sv6ulq3vs.png)

Now with _Android SDK_ installed we _Expo_ will run with _Android_, otherwise it'll throw a error saying that it didn't found the _Android SDK_.

### Installing _ADB_
Now we'll need to install _ADB (Android Debugging Bridge)_, this is what will make the connection between our _Expo_ project on _WSL_ and the _AVD_ on _Windows_ with _WSA_.

To install _ADB_ go to [this link](https://github.com/awake558/adb-win/tree/master/SDK_Platform-Tools_for_Linux), scroll down until you find the markdown and there click on the first `platform tools`, its the one that has _Android Debug Bridge version 1.0.41_ 

![highlighted version of platform-tools to be downloaded](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8luqoec581rou4khxejl.png)

It'll download a zip file on your your _Windows_, move that file to your _WSL_ user root.

> For those who don't know, you can find your _WSL_ _Linux_ on the side of your _File Explorer_. There you can navigate to your user root folder manually in a WYSIWYG way, then paste the file there on your user root folder.

Again on _WSL_ and with the file `platform-tools_r34.0.5-linux.zip` on your user root folder, `unzip` this file and go to the extracted folder `platform-tools`.

On the folder run you'll need to run `./adb connect <WSL IP:WSA PORT>` to create the connection between _WSL_ and _WSA_, but before that lets get that IP and port.

**Getting _WSL_ IP**
To get the _WSL_ IP, on your _WSL_ terminal run `netsh.exe interface ip show address` and look for the _WSL_ interfaces. In my case is these two:

![output of commands of my WSL interfaces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jbktg7x4knlmlgtrsvma.png)

In my specific case I need to get the IP Address from `"vEthernet (WSL (Hyper-V firewall))"`, but your interface name may be different than mine, either way just get one of the _WSL_ IP's and and save it to use later.

**Getting _WSA_ Port**
Go to your _WSA_, on that same page we turned _Developer Mode_ on, check the message it displays right below it and look for the port

![message below developer mode with local IP and port](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzc19dd1kndko3d891dr.png)

For all the tests I made the port was the same, but I'm showing how to get the port just in case!

Getting back to our _WSL_ on the `platform-tools` folder with that _ADB_ command we view before, with your _WSL_ IP and the _WSA_ port run `./adb connect <WSL IP:58526>`

_WSA_ may ask you to allow the _ADB_ connection, if that happens click on "Always allow from this computer" and "Allow"

![WSA connection confirmation window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qoh0bb9mskm4dr6zd85r.png)

Check if your _ADB_ was connected successfully on your _WSA_ running `./adb devices`, if it display something like that we're connected!

![ADB on WSL is connected to WSA](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70rpnobfotkjktollq8s.png)

### Running the Project with _AVD_

Now go again to your project folder and run it with `npm run start:wsl` then press `a` to open _Android_ _AVD_.

It should open two windows from _WSA_, one with the _Expo_ app and another one with your project running, just like this

![expo app and expo project running on two separated windows on WSA](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ips6udfpk9h4d0og239q.png)

And then, congratulations, your _Expo_ project is fully working through _WSL_!

#### Troubleshoot

**`unzip is not defined`**
If you got a issue saying that `unzip command not found` or something like that, this is because you don't have unzip installed on your _WSL_, you just need to [install it](https://www.tecmint.com/install-zip-and-unzip-in-linux/).

**`./adb connect`**
You got a error when try to connect on _ADB_ or nothing simply happens after you run the command, maybe your _WSL_ IP is the wrong one, double check if you typed the IP correctly and also you can try to use another _WSL_ interface IP Address.

----

That's all folks!

I really hope that this tutorial is as useful to you as it was to me to figure out how to make a _Expo_ project run on _WSL_! Feel free to ask any questions down below and thank you for reading it!