Install, build and debug a react native app in WSL2 (Windows Subsystem for Linux) and Ubuntu.
- Install tools in Windows
- Install tools in WSL2
- Create android virtual device in Windows
- Start android virtual device in Windows
- Start adb server in Windows
- Enable access to adb server from WSL2
- Enable access to metro bundler from Windows
- Create react native app in WSL2
- Build app in WSL2
- Debug app in Visual Studio Code from WSL2
- Install WSL2 and Ubuntu, see here
- Install Android Studio, see here
- Install Viusal Studio Code, see here
Installation instructions below uses Open JDK
version. If you want the Official Oracle version see how to install Official JDK 11
- Install java-8-openjdk in WSL2 (sudo apt-get install openjdk-8-jre or use java11 openjdk-11-jre)
- Install Android SDK cmdline tools in WSL2, see here
- Install nodejs in WSL2, see here
Create a virtual device (e.g. Nexus_5X_API_29) in windows with Android Virtual Device Manager from Android Studio.
Android Studio > Configure > AVD Manager
Start Android virtual device (e.g. Nexus_5X_API_29) in windows
adb kill-server
adb -a nodaemon server start
Change firewall rule for adb.exe on first usage in Defender Popup or with Windows Defender Firewall allowing access for the public profile, because the vEthernet (Wsl) adapter belongs to the public profile
Set environment variable to access adb server, WSL_HOST is ip of vEthernet (WSL) interface in windows
export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
export ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037
npx react-native init testapp
Start vs code in WSL2
code .
and install extensions for VS Code
- Remote - WSL
- React Native Tools
VS Code UI runs in windows and the VS Code Server runs in WSL2, see here
Add a launch configuration in file launch.json with specified type
and target
, see this StackOverFlow Answer
Add paraameter in file proguard-rules.pro to ignore okhttp3 warnings
-dontwarn okhttp3.internal.platform.*
Edit npm scripts in package.json
- Run
adb devices
to get<device-name>
"scripts": {
"android": "react-native run-android --variant=debug --deviceId <device-name>",
"start": "react-native start --host 127.0.0.1",
}
First, start metro JavaScript bundler (--host 127.0.0.1
binds bundler to localhost which is forwarded to windows)
yarn start
Then, build and deploy app to device (--deviceId <device-name>
specifies target device to deploy to)
yarn android
Happy hacking!
@Indimeco
I am stuck in a vicious loop, because this current gist got complicated here
the instructions referenced in the that gist, is somehow outdated and this is where it got complicated for me
@Indimeco
Please can you confirm you followed only this current gist and the setups still works for you right now ?
how exactly did you "Install Android SDK on Windows Bash (WSL2) ",
do you know what setups is upto date with the latest updates from android studio and other related things
I have tried to follow the instructions in this gist, which referenced some StackOverflow
The StackOverflow solution as been updated
this update has caught me in a vicious loop, as when i follow a particular config, it only results into another new error,
when i search for the solutions to that error, it instructs me to use an older version of jdk: jdk-8
and the loops begins again