Setting Up Android Development Environment in Windows Subsystem for Linux (WSL)

wsl logo
2 mn read

As developers, we often start our journey on Windows machines, but many of us quickly realize that Windows can be challenging for development work. While Linux offers a more developer-friendly environment, it may not be ideal for other tasks like gaming. Enter Windows Subsystem for Linux (WSL) – a game-changer that allows us to harness the power of Linux within Windows.

In this two-part series, we’ll explore how to set up an Android development environment in WSL. This first post will cover the initial setup, including installing necessary tools and SDKs.

Prerequisites:

  • WSL installed with Ubuntu distro
  • Basic familiarity with command-line operations

Step 1: Installing OpenJDK and Gradle

Android development requires Java Development Kit (JDK) and Gradle. Let’s install them:

sudo apt install openjdk-8-jdk-headless gradle
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Note: You can opt for OpenJDK 11 if preferred, but OpenJDK 8 works well for most purposes.

Step 2: Installing Android Command Line Tools

Next, we’ll download and set up the Android command-line tools. You can get it from this link. (Make sure you get the one for Linux, not Windows)

cd ~
curl https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip -o /tmp/cmd-tools.zip
mkdir -p android/cmdline-tools
unzip -q -d android/cmdline-tools /tmp/cmd-tools.zip
mv android/cmdline-tools/cmdline-tools android/cmdline-tools/latest
rm /tmp/cmd-tools.zip

Step 3: Setting Up Environment Variables

Configure the necessary environment variables. The Android SDK requires some environment variables to be set. Feel free to edit your .bash_profile or export them the way you like!

export ANDROID_HOME=$HOME/android
export ANDROID_SDK_ROOT=${ANDROID_HOME}
export PATH=${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${PATH}

Add these lines to your .bash_profile or preferred shell configuration file for persistence.

Step 4: Accepting SDK Licenses

Before proceeding, we need to accept the SDK licenses. we need to agree to some licenses. You probably should read them (if you haven’t already).

yes | sdkmanager --licenses

Step 5: Installing SDK Components

Finally, let’s install the necessary SDK components.

sdkmanager --update
sdkmanager "platforms;android-30" "build-tools;30.0.3"

You can view all available components and their versions with

Conclusion

With these steps completed, you now have a basic Android development environment set up in WSL. You can build Android apps from within WSL, but there’s more to explore. In the next post, we’ll dive into advanced topics like setting up emulators, connecting USB devices, and integrating with IDEs for a complete development experience.

Keep an eye out for part two(Here), where we’ll tackle these exciting challenges and take your WSL Android development setup to the next level!

Leave a Reply

Your email address will not be published. Required fields are marked *

Reading is essential for those who seek to rise above the ordinary.

ABOUT US

The internet as we know is powerful. Its underlying technologies are transformative, but also, there’s a plethora of haphazard information out there.We are here to serve you as a reliable and credible source to gain consistent information

© 2024, cloudiafrica
Cloudi Africa