To me, this process have always seemed error prone, because you're dealing with multiple languages and build-tools.
This monorepo uses Yarn workspaces and TypeScript to support a modular React Native project.
VS Code UI runs in windows and the VS Code Server runs in WSL2, see hereĪdd a launch configuration in file launch.A React Native monorepo boilerplate supporting multiple platforms: Android, iOS, macOS, Windows, web, browser extension, Electron.
Start metro builder npx react-native startīuild app, set device as parameter deviceId from result of adb devices npx react-native run-android -variant=debug -deviceId emulator-5554ĭebug app in Visual Studio Code from WSL2
pro to ignore okhttp3 warnings -dontwarn .* Iex "netsh interface portproxy add v4tov4 listenport=8081 listenaddress=127.0.0.1 connectport=8081 connectaddress=$WSL_CLIENT"Ĭreate react native app in WSL2 npx react-native init AwesomeProjectĪdd parameter in file proguard-rules. $WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+)' Socat relays the requests from wsl2 to windows using the following command: socat -d -d TCP-LISTEN:5037,reuseaddr,fork TCP:$(cat /etc/nf | tail -n1 | cut -d " " -f 2):5037Įnable port fowarding to metro bundler from WindowsĪdd port fowarding from windows to metro bundler running in WSL2, listening on port 8081,Įnabling a connection via adb from the emulator to WSL2.īelow, in Powershell: iex "netsh interface portproxy delete v4tov4 listenport=8081 listenaddress=127.0.0.1" | out-null
One solution is to use socat (thanks to the environment variable if necessary. Somtimes adb crashes using the environment variable config. Set environment variable to access adb server, WSL_HOST is ip of vEthernet (WSL) interface in windows export WSL_HOST=$(tail -1 /etc/nf | cut -d' ' -f2)Įxport ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037 The vEthernet (Wsl) adapter belongs to the public profile Enable access to adb server from WSL2 With Windows Defender Firewall allowing access for the public profile, because Start adb server in Windows adb kill-serverĬhange firewall rule for adb.exe on first usage in Defender Popup or Nexus_5X_API_29) in windows "C:\Program Files (x86)\Android\android-sdk\emulator\emulator.exe" -avd Nexus_5X_API_29 Nexus_5X_API_29) in windows with Android Virtual Device Manager from Android Studio. PATH=$PATH:$ANDROID_SDK_ROOT/platform-toolsĮxport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64Ĭreate a virtual device (e.g. bash_profile export ANDROID_HOME=/home/xxx/Android/cmdline-tools/latestĮxport ANDROID_SDK_ROOT=/home/xxx/Android