Created
August 10, 2025 18:13
-
-
Save PowerX-NOT/0f9e35093c80a7cb253c290875a92ffe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| ANDROID_SDK_DIR="$HOME/android-sdk" | |
| # Find the first commandlinetools-linux*.zip in home directory | |
| CMDLINE_TOOLS_ZIP=$(ls $HOME/commandlinetools-linux*.zip 2>/dev/null | head -n 1 || true) | |
| if [ -z "$CMDLINE_TOOLS_ZIP" ]; then | |
| echo "ERROR: No commandlinetools-linux*.zip file found in $HOME" | |
| echo "Please download the Android command line tools from:" | |
| echo "https://developer.android.com/studio#cmdline-tools" | |
| echo "Place the zip file in your home directory and run this script again." | |
| exit 1 | |
| fi | |
| echo "Using command line tools zip: $CMDLINE_TOOLS_ZIP" | |
| echo "Creating SDK directory at $ANDROID_SDK_DIR" | |
| mkdir -p "$ANDROID_SDK_DIR" | |
| echo "Extracting $CMDLINE_TOOLS_ZIP to $ANDROID_SDK_DIR" | |
| unzip -q -o "$CMDLINE_TOOLS_ZIP" -d "$ANDROID_SDK_DIR" | |
| echo "Fixing cmdline-tools directory structure..." | |
| if [ -d "$ANDROID_SDK_DIR/cmdline-tools/bin" ]; then | |
| mv "$ANDROID_SDK_DIR/cmdline-tools" "$ANDROID_SDK_DIR/cmdline-tools_temp" | |
| mkdir -p "$ANDROID_SDK_DIR/cmdline-tools" | |
| mv "$ANDROID_SDK_DIR/cmdline-tools_temp" "$ANDROID_SDK_DIR/cmdline-tools/latest" | |
| fi | |
| # Add environment variables to ~/.bashrc if not already present | |
| if ! grep -q "ANDROID_SDK_ROOT" "$HOME/.bashrc"; then | |
| echo "Adding Android SDK environment variables to ~/.bashrc" | |
| { | |
| echo "" | |
| echo "# Android SDK environment variables" | |
| echo "export ANDROID_HOME=$ANDROID_SDK_DIR" | |
| echo "export ANDROID_SDK_ROOT=$ANDROID_SDK_DIR" | |
| echo "export PATH=\$PATH:\$ANDROID_HOME/cmdline-tools/latest/bin" | |
| echo "export PATH=\$PATH:\$ANDROID_HOME/platform-tools" | |
| } >> "$HOME/.bashrc" | |
| fi | |
| # Export environment variables for current shell | |
| export ANDROID_HOME="$ANDROID_SDK_DIR" | |
| export ANDROID_SDK_ROOT="$ANDROID_SDK_DIR" | |
| export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools" | |
| echo "Installing essential SDK packages..." | |
| yes | sdkmanager --install "platform-tools" "build-tools;34.0.0" | |
| echo "Installation complete!" | |
| echo "Please run 'source ~/.bashrc' or restart your terminal to apply environment changes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment