Skip to content

Instantly share code, notes, and snippets.

@mwoodpatrick
Forked from xquangdang/rn-with-wsl-wsa.md
Last active October 3, 2024 12:43
Show Gist options
  • Save mwoodpatrick/91606d1cff580265470fa604f900adfc to your computer and use it in GitHub Desktop.
Save mwoodpatrick/91606d1cff580265470fa604f900adfc to your computer and use it in GitHub Desktop.
Develop React Native app with WSL and WSA

Develop React Native app with WSL and WSA

Requirement

  • Windows Subsystem for Linux 2 (WSL2)
  • Windows Subsystem for Android (WSA)
  • NodeJS install inside WSL2

Steps

WSA

  1. Enable developer mode for WSA image

WSL2

This tutorial will run on Ubuntu 20.04

  1. Install Android debug bridge (adb)
$ sudo apt install adb
  1. Connect to WSA

image

  • Connect to WSA via IP
$ adb connect <wsa-ip>

image

  • Make sure ADB connect successfully
$ adb devices -l
List of devices attached
172.21.210.88:5555     device product:windows_x86_64 model:Subsystem_for_Android_TM_ device:windows_x86_64 transport_id:4

React Native setup

I'll follow tutorial on ReactNative.dev

# Assuming that you have Node 12 LTS or greater installed, you can use npm to install the Expo CLI command line utility
$ sudo npm install -g expo-cli
# Then run the following commands to create a new React Native project called "AwesomeProject"
$ expo init AwesomeProject

cd AwesomeProject
$ npm start # you can also use: expo start

Select Run on Android device/emulator in expo web client image

FAQ

@TheoLAFARGE
Copy link

you're the best

@oMelqs
Copy link

oMelqs commented Sep 25, 2024

how can i run react-native-cli project?

@TuKun33
Copy link

TuKun33 commented Oct 2, 2024

my wsa unable to hot reload
and i reinstall the debug apk also not working, it is always install the old apk

@TuKun33
Copy link

TuKun33 commented Oct 3, 2024

my wsa unable to hot reload and i reinstall the debug apk also not working, it is always install the old apk

Maybe it's a network issue. I found that my WSA application suddenly couldn't connect to the internet. I turned off "local network access" and restarted WSA, and it started working
image

@oMelqs
Copy link

oMelqs commented Oct 3, 2024

@TuKun33 i have a similar problem, solved when i changed .wslconfig file on windows user home folder

mine look like that

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=8GB 

# Sets the VM to use two virtual processors
processors=8

# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=8GB

#	Boolean to turn on or off nested virtualization, enabling other nested VMs to run inside WSL 2. Only available for Windows 11.
nestedVirtualization=true

# set mirrored network settings
networkingMode=mirrored**

this last setting was what resolved it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment