Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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

@PowerMogli
Copy link

PowerMogli commented Oct 12, 2020

thank you so much! so much lost time before

@steveclarke
Copy link
Author

steveclarke commented Oct 12, 2020

thank you so much! so much lost time before

Glad it helped. I haven't figured out how to connect to emulator or physical device yet. Feel free to fork and share your config if you get that part working.

@ReazerDev
Copy link

ReazerDev commented Nov 26, 2020

To connect to a physical device. Connect the device to a USB Port, in your windows cmd run adb tcpip 5555. Then in your WSL cmd run adb connect IP_ADDRESS_OF_PHONE:5555. You can find the IP_ADDRESS_OF_PHONE aprt, by going into your phone's wifi settings, clicking on the wifi you are connected to click on Advanced and then you see an IP address field. That's it

@ReazerDev
Copy link

ReazerDev commented Nov 26, 2020

Oh and btw. really great tutorial. Saved me a ton of time

@steviesteve
Copy link

steviesteve commented Dec 7, 2020

Super helpful thanks!

@ramitd1995
Copy link

ramitd1995 commented Jan 17, 2021

Great work Steve, this works like a charm and saved a lot of time.

@ariefitriadin
Copy link

ariefitriadin commented Feb 11, 2021

Great, super helpful, TQ

@mateusleon
Copy link

mateusleon commented Apr 7, 2021

I`ve struggled a little bit with the step after unzipping and placing the paths into $PATH variable. This thread helped me to figure out the issues: https://stackoverflow.com/questions/60440509/android-command-line-tools-sdkmanager-always-shows-warning-could-not-create-se

@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

piyush460 commented Nov 17, 2021

Thankyou , it helps me a lot.

@julian55455
Copy link

julian55455 commented Apr 17, 2022

@jason-s-yu thanks
it works

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