Developing React Native with Expo/Android Emulators on WSL2 — Linux Subsystem

Mo Akbari
4 min readJul 5, 2023

--

Hello all, my name is Mo and I’m a software engineer who has faced a lot of problems trying do develop with expo and react native on WSL2. I ran into a lot of issues trying to connect to an android studio installation on my windows system, from code and installations located on the Linux subsystem, I managed to figure it out so I thought I’d share here for anyone else who comes across this! For reference I’m on Windows 10 version 22H2 and Ubuntu 20.04.

Step 1 // Download and install Android Studio.

Step 2 // Open the Android Studio app, click More Actions(3 dots) and then select SDK Manager. If you already have a project open click File then Settings.

Step 3 // If you’re not there already, navigate into Appearance & Behavior > System Settings > Android SDK. From the SDK Platforms tab, select the latest Android version (API level).

Step 4 // Click on the SDK Tools tab and make sure you have at least one version of the Android SDK Build-Tools and Android Emulator installed.

Step 5 // Click Apply and OK to install the Android SDK and related built-tools.

Step 6 // Copy the bash script below and replace <user> with your Windows username.

echo -e "\n# Android\nexport ANDROID_HOME=/mnt/c/Users/<user>/AppData/Local/Android/Sdk\nexport WSLENV=ANDROID_HOME/p" >> $HOME/.bashrc && source $HOME/.bashrc

Step 7 // Paste and run the script in your ubuntu terminal. This will add the below lines to your .bashrc file and also reload it.

This adds these as a Linux environment variable & also in the shared WSL environment

Step 8 // Due to how the Linux subsystem interacts with Windows, when you try to run the expo android script now you will receive an ENOENT error due to the executable having a file extension. To get around this we will be creating a copy of the tool that Linux will be able to use. Below is the bash script to run in your ubuntu terminal. Again, replace <user> with your Windows username.

sudo cp /mnt/c/Users/<user>/AppData/Local/Android/sdk/platform-tools/adb.exe /mnt/c/Users/<user>/AppData/Local/Android/sdk/platform-tools/adb

Step 9 // Close and relaunch Android Studio for the environment variables to be reloaded.

Step 10 // Next we will update the default terminal opened when we launch Android Studio. To do this we must first find the directory of the executable shell, I’ll show where mine was located below. Once you located the path, you need to copy the address as documented below

Step 11 // Navigate back to Android Studio and open up a project, head over to Settings > Tools > Terminal. Then we will change the shell path to what we just copied and add the name of the executable to the end of it, example below. Then click Apply and OK.

Step 12 // Open up your project within Android Studio, ensure you have an emulator running, and run your script and enjoy your development experience!

--

--