Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jason-s-yu/30375db45c1f71c1259e042d216e4bd3 to your computer and use it in GitHub Desktop.
Save jason-s-yu/30375db45c1f71c1259e042d216e4bd3 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 update

sudo apt install openjdk-8-jdk-headless

Android SDK

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;30.0.3" "platform-tools" "platforms;android-30" "tools"
sdkmanager --licenses

sudo apt install gradle

Please find the latest version of Android SDK at: https://developer.android.com/studio/#downloads (scroll to the bottom of the page under the section "Command Line Tools only"

Used a combinaton of these gists:

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

https://stackoverflow.com/questions/65262340/cmdline-tools-could-not-determine-sdk-root

@jason-s-yu
Copy link
Author

Thanks for this. The third line has the old zip name. Should be unzip commandlinetools-linux-7302050_latest.zip -d Android/cmdline-tools

@mikkomcmenamin sorry for the late reply. Thank you, I've edited the OP

@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

@jramiresbrito
Copy link

Thank you! It really helped

@alindafortunate
Copy link

Hello Team, i followed the steps above but i am getting this error

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocationsProvider has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Any support

@YoanAncelly
Copy link

Thank you ! That was very helpful

@Kulunkulu
Copy link

Is this still working in Aug15th, 2024?
I've read so many threads and right now my head is spinning

@Kulunkulu
Copy link

@devnshankar
Do you have a working config for Windows 10?
if Windows 11 is the only way, can you please be more detailed on how to do it in Windows 11

@Kulunkulu
Copy link

Thank you @devnshankar

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