WSL for Developers!: Installing the Android SDK
Tags: wsl, wsl2, android, mobile
Published: 2022-06-01 19:13:38

---
title: WSL for Developers!: Installing the Android SDK
published: true
date: 2022-06-01 19:09:34 UTC
tags: wsl, wsl2, android, mobile
canonical_url: https://halimsamy.com/wsl-for-developers-installing-the-android-sdk
series: WSL for Developers!
cover_image: https://halimsamy.com/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1654460656427%2FATv5LQRg8.jpg%3Fw%3D1600%26h%3D840%26fit%3Dcrop%26crop%3Dentropy%26auto%3Dcompress%2Cformat%26format%3Dwebp&w=1920&q=75
---

## Introduction

As any developer, you have probably started your career with a Windows machine, after some time you will begin to notice how Windows is horrible with development stuff (at least this is my opinion). For me, I wanted to switch to Linux so badly, Guess what? I did actually. Out of the blue Windows were a part of the past. and used Linux for almost 2 years! everything was perfect except for one thing that you probably know. Yes, thats gaming. for me, Xbox wasnt enough. I wanted a PC gaming experience. (note: dual boot is a pain in the ass)

In the meanwhile, Windows you know, was kind of getting better over time, with the best achievement of Microsoft arrived (that is WSL) I have switched back to Windows. Now I have both Windows gaming and Linux superpower!

## About this series

In this series (WSL for Developers!) I will document how I do I use WSL for my different development, for the sake of this series I will assume you have already installed WSL with the Ubuntu distro. You can search online for how to install WSL. Microsoft has an [official documentation for installing WSL](https://docs.microsoft.com/en-us/windows/wsl/install).

## Installing OpenJDK and Gradle

You probably know that Android development requires the JDK and Gradle to be installed. Lets get this done.

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

You can install OpenJDK 11 if you want, for me I didn't face any issues with both.

## Installing Android Command Line Tools

First, we need to get the latest Android command-line tools. You can get it from [this link](https://developer.android.com/studio#downloads). (Make sure you get the one for Linux, not Windows)

```bash
cd ~ # Make sure you are at home!
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 # delete the zip file (optional)
```

## Setting up 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!

```bash
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}
```

## Accepting SDK licenses

You got it right? we need to agree to some licenses. You probably should read them (if you havent already).

```bash
yes | sdkmanager --licenses
```

## Installing SDK components

Now the final part, let's install what we need, feel free to adjust the versions or components depending on your needs!

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

You can get a list of all the components available and their versions by running:

```bash
sdkmanager --list
```

## Final thoughts

Up to this point, you can build your android apps from inside WSL, but isnt this all about development? where is the emulator? or even attaching a device with USB? What about my IDE and coding experience? Well to be honest those are topics for the up coming article of the series (WSL for Developers!). I like lightweight articles thats my style of writing. Dont worry there is more coming next!

## Thanks!

Thanks for reading and coming to the end. I wish that you have enjoyed it and of course found it useful. I would like to thank you that you have given my first article/post a chance and I hope that I will get better over time.