Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save steveclarke/d988d89e8cdf51a8a5766d69ecb07e7b to your computer and use it in GitHub Desktop.
Save steveclarke/d988d89e8cdf51a8a5766d69ecb07e7b to your computer and use it in GitHub Desktop.

Install Android SDK CLI Ubuntu 20.04 WSL2 (Work in Progress)

Install Java 8

sudo apt install openjdk-8-jdk-headless

Android SDK

wget https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
mkdir -p Android/Sdk
unzip commandlinetools-linux-6200805_latest.zip -d Android/Sdk

export ANDROID_HOME=$HOME/Android/Sdk
# 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/platform-tools:$PATH"

sdkmanager --sdk_root=${ANDROID_HOME} "tools"

sdkmanager --update
sdkmanager --list
sdkmanager "build-tools;28.0.3" "platform-tools" "platforms;android-28" "tools"
sdkmanager --licenses

sudo apt install gradle

Note: you can get an updated Android SDK link from https://developer.android.com/studio/#downloads

Used a combinaton of these gists: https://gist.github.com/fedme/fd42caec2e5a7e93e12943376373b7d0 https://gist.github.com/jjvillavicencio/18feb09f0e93e017a861678bc638dcb0

Background on the update to command line tools from android sdk https://stackoverflow.com/a/61176718

@asafeca
Copy link

asafeca commented May 23, 2021

many thanks!

@jason-s-yu
Copy link

jason-s-yu commented Jun 5, 2021

The latest version of cmdline tools (7302050_latest) seems to have a different directory structure. The folder is now called cmdline-tools instead of tools so when you extract the folder it won't work as expected. sdkmanager also seems to expect to want to be in ${ANDROID_HOME}/cmdline-tools/latest/bin but extracting it in ANDROID_HOME will just give you ${ANDROID_HOME}/cmdline-tools/bin...

So it looks like unzipping the newest version to ${ANDROID_HOME}/cmdline-tools/cmdline-tools will fix this, and remove the need to run sdkmanager --sdk_root.... Easiest way might just be to mkdir -p Android/cmdline-tools and unzip to there & rename the second cmdline-tools to latest

Not sure how this whole forking gists thing is supposed to work but here are the changes I used: https://gist.github.com/jason-s-yu/30375db45c1f71c1259e042d216e4bd3

wget https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip
mkdir -p Android/cmdline-tools
unzip commandlinetools-linux-6200805_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
sdkmanager "build-tools;30.0.3" "platform-tools" "platforms;android-30" "tools"
sdkmanager --licenses

@mnirm
Copy link

mnirm commented Oct 24, 2021

Thank you very much. Very easy to use ❤

@joaop221
Copy link

joaop221 commented Nov 2, 2021

I recommend to add the update command and the unzip installation in this steps:

sudo apt update && sudo apt install openjdk-8-jdk-headless unzip

@piyush460
Copy link

Thankyou , it helps me a lot.

@julian55455
Copy link

@jason-s-yu thanks
it works

@ArnyminerZ
Copy link

That works great @jason-s-yu, thank you very much!

@ArnyminerZ
Copy link

I've found myself into trouble. I'm getting this from Android Studio:

Build-tool 33.0.0 is missing AAPT at \\wsl$\Ubuntu\home\arnyminerz\Android\build-tools\33.0.0\aapt.exe
Build-tool 33.0.0 is missing AAPT at \\wsl$\Ubuntu\home\arnyminerz\Android\build-tools\33.0.0\aapt.exe

Any clue why this is happenning? I've tried creating symbolic links from aapt.exe to aapt but it fixes nothing 😢

@eduardo-sm
Copy link

This worked to install the Android SDK. Thanks. Now I'm facing a different issue.

I can't make adb find my devices in WSL2. I have the same version of adb in both windows and wsl (33.0.3-8952118).

The trick of adb tcpip 5555 only worked on WSL1 but it doesn't on WSL2.

I've also tried usbip-win to share the USB port like follows

usbipd wsl attach --busid <BUSID>

But it always fails saying that the device is busy when adb is ON in the device.

Is there any other alternative or step that is required to make adb work in WSL2?

@mirao
Copy link

mirao commented Mar 11, 2023

Just in case you want to install Android Studio with functional GUI from snap in Ubuntu 22.04 in WSL2 (Windows 11), follow these steps:

  1. Enable systemd
  2. Run this
sudo snap install android-studio --classic
sudo apt install openjdk-11-jre-headless libxrender1 libxtst6 libxi6

@bswck
Copy link

bswck commented Aug 15, 2023

sudo apt install openjdk-17-jdk for the latest release.

@sazonov-src
Copy link

+++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment