Android Development using WSL and WSA
Solomon Razaq
Founding Engineer at Linkup | Software Engineer at Kandua | Web3 Enthusiast
The last two days have been nothing short of an adventure. I aimed to test our React Native application on my Windows computer, but there was a catch. Our codebase is incompatible with Windows. Hence we use Ubuntu in the Windows Subsystem for Linux (WSL).
I owe a huge thanks to the extensive online community, without which I would have struggled to find success eventually.
Before I dive into the correct approach, I'd like to briefly outline my journey, detailing some possibly functional but incorrect methods. I've included references for those interested in the specific challenges I encountered.
I commenced with the React Native documentation for Windows and Linux but didn't make much headway. I realized the Android SDK must be inside WSL, not on my Windows machine.
After some research, I found a document detailing installing the Android SDK CLI on Ubuntu 20.04 WSL2. However, after going through the process, I discovered it doesn't work with the latest version of Android command-line tools. After some tinkering, I moved on to another guide.
I then considered using Windows Subsystem for Android (WSA) but hit a roadblock as WSA is unavailable outside the US and requires an Amazon US account.
Without delving too much into the extensive debugging, researching, and experimentation, let's get straight to the correct way of setting it all up from scratch.
Part 1 - Setting Up Your Windows Machine and WSA:
Part 2 - Installing Necessary Tools in WSL:
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip
mkdir -p Android/cmdline-tools
unzip commandlinetools-linux-8512546_latest.zip -d Android/cmdline-tools
mv Android/cmdline-tools/cmdline-tools Android/cmdline-tools/latest
export ANDROID_HOME=$HOME/Android
# Make sure emulator path comes before tools. Had trouble on Ubuntu with emulator from /tools being loaded
# instead of the one from /emulator
export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/cmdline-tools/latest:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
# don't need this anymore
# sdkmanager --sdk_root=${ANDROID_HOME} "tools"
sdkmanager --update
sdkmanager --list
# find current version
sdkmanager --list | grep build-tools
# change the version below with whatever version is downloaded
sdkmanager "build-tools;34.0.2" "platform-tools" "platforms;android-34" "tools"
sdkmanager --licenses
Credit to GitHub user "jason-s-yu" for the above snippet minus a minor tweak.
(Note: React Native doesn't support Gradle 8, so you can't install the latest version. Use SDKMAN to install the correct version.)
领英推荐
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install gradle 7.5.1
# if you have multiple versions you can set the current one
sdk use gradle 7.5.1
Remember, in the context of a typical React Native project, Gradle is run via the Gradle Wrapper, which uses the version defined in android/gradle/wrapper/gradle-wrapper.properties. Changing the system-wide Gradle version may not affect your project. You might still need to change the distributionUrl in the gradle-wrapper.properties file.
As of the recent update to WSA, it no longer has its IP address but uses the host's IP address. i.e., 192.168.50.3. My antivirus also interfered with this, so I have my antivirus and firewall disabled.
3. Connect to WSA. I am not too sure about the port. Some online resources said to use 5555 or 5554, but for me, it was the port in the WSA settings (58526).
# adb connect <host-ip:port>
adb connect 192.168.50.3:58526
You should receive a pop-up confirming the device's authenticity, and running "adb devices" should list your device.
From this point, you can open your solution, run Metro, and execute the app. Once installed, your app will launch.
I hope this guide proves helpful and saves others from two days of intensive research. My main takeaway was that if it seems exceedingly complex to get something working in Windows, you're missing something fundamental.
Here's a list of other resources I found helpful, especially for those who don't want to use WSA or are interested in understanding the alternatives better:
Remember, no solution is one-size-fits-all. I encourage you to try and find the setup that works best for you. Happy coding!
Director: Disciples Ministries International
1 年nice work to achievement. God bless
Senior Software Engineer at Asseti
1 年Nice one! I tried and failed last time ;)
Director, Savills Earth Advisory | Sustainability | Net Zero | ESG | Social Value
1 年Nice work Solomon Razaq!