-
Star
(293)
You must be signed in to star a gist -
Fork
(79)
You must be signed in to fork a gist
-
-
Save jjvillavicencio/18feb09f0e93e017a861678bc638dcb0 to your computer and use it in GitHub Desktop.
| cd /home/<user>/ | |
| sudo apt-get install unzip | |
| wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip | |
| unzip sdk-tools-linux-4333796.zip -d Android | |
| rm sdk-tools-linux-4333796.zip | |
| sudo apt-get install -y lib32z1 openjdk-8-jdk | |
| export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 | |
| export PATH=$PATH:$JAVA_HOME/bin | |
| printf "\n\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc | |
| cd Android/tools/bin | |
| ./sdkmanager "platform-tools" "platforms;android-26" "build-tools;26.0.3" | |
| export ANDROID_HOME=/home/<user>/Android | |
| export PATH=$PATH:$ANDROID_HOME/tools | |
| export PATH=$PATH:$ANDROID_HOME/platform-tools | |
| printf "\n\nexport ANDROID_HOME=/home/<user>/Android\nexport PATH=\$PATH:\$ANDROID_HOME/tools\nexport PATH=\$PATH:\$ANDROID_HOME/platform-tools" >> ~/.bashrc | |
| android update sdk --no-ui | |
| sudo apt-get install gradle | |
| gradle -v | |
| adb start-server |
I got the below exception when I run ./sdkmanager "platform-tools" "platforms;android-26" "build-tools;26.0.3". Any Idea how I can resolve this?
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
I got the below exception when I run ./sdkmanager "platform-tools" "platforms;android-26" "build-tools;26.0.3". Any Idea how I can resolve this?
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more
Install jdk 8
printf "\n\nexport ANDROID_HOME=/home//Android\nexport PATH=$PATH:$ANDROID_HOME/tools\nexport PATH=$PATH:$ANDROID_HOME/platform-tools" >> ~/.bashrc
Be careful! When you run this command multiple times it will end up making .bashrc larger and larger.
Ideally this cmd would contain some if to test whether .bashrc was already updated before.
Help me
i'm pool and we need a moneys please help me i'm myanmar please help My countryπ
Thank you all for this! My version of the scripts after looking into all the comments...
sudo apt-get update
cd
sudo apt-get install unzip zip
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d Android
rm sdk-tools-linux-4333796.zip
sudo apt-get install -y lib32z1 openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
printf "\n\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc
cd Android/tools/bin
### check latest platform and build-tools versions (29, 29.0.2)
./sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2"
export ANDROID_HOME=~/Android
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
printf "\n\nexport ANDROID_HOME=~/Android\nexport PATH=\$PATH:\$ANDROID_HOME/tools\nexport PATH=\$PATH:\$ANDROID_HOME/platform-tools" >> ~/.bashrc
./sdkmanager --update
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
### check latest grade version
sdk install gradle 5.5.1
gradle -v
### run "adb start-server" in powershell
Excellent script thanks for sharing. I think you can update it by replacing /home/<user>/ with $HOME. Example:
export ANDROID_HOME="$HOME/Android"
And ANDROID_HOME environment variable was deprecated. It's recommended write as:
export ANDROID_HOME="$HOME/Android"
export ANDROID_SDK_ROOT="$ANDROID_SDK_ROOT"
THIS WORKS!!!! FINALLY!!!
lol
Jokes aside, I tried 6+ different things which led to dozens of StackOverflow Questions, GitHub Threads, etc. and all of them failed except this beautiful gem!
@jjvillavicencio Thank you! (Gracias!) @unicornlab-brylleg Thank you for the update!
is this "sdk-tools-linux-4333796.zip" thing the latest version? anyone knows where to check?
no @rizkysyazuli, the last version is "commandlinetools-linux-7302050_latest.zip", you can check how install here too:
https://gist.github.com/jason-s-yu/30375db45c1f71c1259e042d216e4bd3
Remove all paths with spaces in WSL by adding this line in /etc/profile
PATH=$(echo $PATH | sed 's|:/mnt/[a-z]/[a-z_]*\?/\?[A-Za-z]* [A-Za-z]* \?[A-Za-z]*\?[^:]*||g')
There are other tools such as buildroot that do not work when there are spaces in PATH.
Wonderful!
So, after successfully installing, how do you resolve references while interacting with the code?
You can easily replace <user> with $USER in the script. That will make things easier since we don't have to replace the any more... It will automatically get the current user ;)
This worked flawlessly thank you so much!
Thank you, was useful!
java 11 version?
You can easily replace
<user>with$USERin the script. That will make things easier since we don't have to replace the any more... It will automatically get the current user ;)
+1000000
Also, the android call on L16 can be changed to sdkmanager, since android as a command is deprecated
Thank you so much!!!
@Kousthubh02
/usr/bin/java is a symlink. I get the following:
ls -l $(which java)
lrwxrwxrwx 1 root root 22 Jan 28 23:07 /usr/bin/java -> /etc/alternatives/java
ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Jan 28 23:07 /etc/alternatives/java -> /usr/lib/jvm/java-17-openjdk-amd64/bin/java
echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
what does echo $JAVA_HOME give you?
You may need to add export JAVA_HOME=\path\to\java\install\location to your ~/.bashrc file and add export PATH=\path\to\java\install\location\bin;"$PATH" as well.
@5p0ng3b0b please can you confirm is the original gist above still works Aug 15th, 2024
I have been following different threads and gists referencing StackOverflow, in the StackOverflow, they are saying different things
for example you are suppose to move tools into cmdline-tools, only for an updated comment saying a new thing
i am so confused right now
no @rizkysyazuli, the last version is "commandlinetools-linux-7302050_latest.zip", you can check how install here too: https://gist.github.com/jason-s-yu/30375db45c1f71c1259e042d216e4bd3
Thanks for the link, worked like a charm.
cd ~/
sudo apt update
sudo apt install unzip
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d Android
rm sdk-tools-linux-4333796.zip
sudo apt install -y lib32z1 openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
printf "\n\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.bashrc
cd Android/tools/bin
./sdkmanager "platform-tools" "platforms;android-36" "build-tools;36.0.0"
export ANDROID_HOME=$HOME/Android
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
printf "\n\nexport ANDROID_HOME=$HOME/Android\nexport PATH=\$PATH:\$ANDROID_HOME/tools/bin\nexport PATH=\$PATH:\$ANDROID_HOME/platform-tools" >> ~/.bashrc
android update sdk --no-ui
sudo apt install gradle
gradle -v
adb start-serverFor latest tools as of May 11 2025 (36.0.0)
and for zsh... (36.0.0)
cd ~/
sudo apt update
sudo apt install unzip
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d Android
rm sdk-tools-linux-4333796.zip
sudo apt install -y lib32z1 openjdk-8-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
printf "\n\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64\nexport PATH=\$PATH:\$JAVA_HOME/bin" >> ~/.zshenv
cd Android/tools/bin
./sdkmanager "platform-tools" "platforms;android-36" "build-tools;36.0.0"
export ANDROID_HOME=$HOME/Android
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
printf "\n\nexport ANDROID_HOME=$HOME/Android\nexport PATH=\$PATH:\$ANDROID_HOME/tools/bin\nexport PATH=\$PATH:\$ANDROID_HOME/platform-tools" >> ~/.zshenv
android update sdk --no-ui
sudo apt install gradle
gradle -v
adb start-serverMuch thanks @jasonm23
You all are rockstars thank you @jasonm23 and @jjvillavicencio
This is setup guide I used to install headless android studio in wsl2. courtesy: gemini pro
π οΈ Complete WSL2 Android SDK Setup Guide
This guide ensures you have a working sdkmanager, platform tools (adb, fastboot), and the necessary Android platform 36 components installed and accessible from your WSL2 terminal.
1. βοΈ Prerequisites and Setup
This assumes you have already downloaded and unzipped the Android Command-line Tools (e.g., to $HOME/Android/cmdline-tools).
1.1. Create the Directory Structure
Make sure your directory structure looks like this. If you haven't, run:
mkdir -p $HOME/Android/cmdline-tools1.2. Correctly Place the cmdline-tools
Move the contents of the unzipped cmdline-tools folder (which should contain a bin, lib, NOTICE.txt, etc. directory/files) into a directory named latest:
# Assuming you unzipped the tools to ~/Downloads/cmdline-tools-linux
mv ~/Downloads/cmdline-tools-linux $HOME/Android/cmdline-tools/latest(The sdkmanager executable must be in $HOME/Android/cmdline-tools/latest/bin/)
2. π Configure Environment Variables
You must add the necessary paths to your shell configuration file (~/.bashrc or ~/.zshrc) so the system can find sdkmanager and adb from anywhere.
Open your shell configuration file:
nano ~/.bashrc # or ~/.zshrcAdd the following block to the end of the file:
# --- Android SDK Configuration ---
export ANDROID_HOME=$HOME/Android
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
# ---------------------------------2.1. Load the New Configuration
Apply the changes to your current terminal session:
source ~/.bashrc # or ~/.zshrc3. π₯ Install SDK Packages
Now that the sdkmanager command is available in your PATH, you can install the required components.
Use the command you initially wanted to run, but without the ./ prefix:
sdkmanager --install "platform-tools" "platforms;android-36" "build-tools;36.0.0""platform-tools": Installsadb,fastboot, etc."platforms;android-36": Installs the Android 36 SDK platform files."build-tools;36.0.0": Installs the necessary build tools (version 36.0.0 is used as a reference).
4. β Accept Licenses
The SDK will not work until you accept the licenses. Use the sdkmanager for this as well:
yes | sdkmanager --licenses5. π¬ Verification and ADB Check
Check if everything is installed correctly:
Step 5.1: Verify adb Path
which adbExpected Output: /home/youruser/Android/platform-tools/adb (or similar)
Step 5.2: Verify SDK Platform
ls $ANDROID_HOME/platformsExpected Output: You should see a folder like android-36 listed.
Step 5.3: Check for Connected Devices (ADB)
To see devices, remember to use the correct command:
adb devicesExpected Output (if no device is connected):
List of devices attached
If you still get Command 'android' not found, remember that android is obsolete and has been replaced by sdkmanager and avdmanager.
This comprehensive list of steps should serve as a complete reference for your WSL2 Android SDK environment setup.

If downloading the up-to-date cmdline-tools from the Android Studio website, you'll need to change the directory structure in order for you to be able to run the
./sdkmanager./home/ben/cmdline-tools/bin -> /home/ben/Android/cmdline-tools/latest/binworked for me.
https://stackoverflow.com/questions/65262340/cmdline-tools-could-not-determine-sdk-root