Setting Up Android SDK Environment on MAC OS

  1. Install the Android command-line tools. Go to Android Developer and download the tools that match your operating system.

    ../../_images/android-command-line-tool.png

    You can use wget on the command line to download the tools package, or download and extract it from the browser.

    You can copy the download link from the above Android Developer site, and then use the following command.

    wget https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip?hl=zh-cn
    mkdir -p Android/cmdline-tools
    unzip commandlinetools-mac-11076708_latest.zip?hl=zh-cn -d Android/cmdline-tools
    mv Android/cmdline-tools/cmdline-tools Android/cmdline-tools/latest
    
  2. Configure the relevant environment.

    Install Java. (If you have previously installed and configured Java, you need to check if your JDK is compatible with the command-line tools. If the version is compatible, you can skip the following steps about configuring the Java environment.)

    We use JDK-17 to run the Android emulator.
    sudo brew install openjdk@17
    

    Open your .bashrc file.

    sudo nano ~/.zshrc
    

    Add the following content at the end of the file.

    export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
    export ANDROID_HOME="/Users/your_id_name/the_path_you_store_commandline_tools/Android"
    export PATH="$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/tools/bin:$ANDROID_HOME/cmdline-tools/latest:$ANDROID_HOME/platform-tools:$PATH"
    
    Ensure that the PATH configuration matches the path where you store the relevant tools.

    Finally, reload the .zshrc file to apply the changes immediately to the current terminal session.

    source ~/.zshrc
    
  3. Verify whether sdkmanager is successfully installed.

    sdkmanager --update
    sdkmanager --list
    sdkmanager --licenses
    

    If you receive the following message, the installation is successful.

    ../../_images/sdkmanager-licenses.png

    You can learn more from the common commands of sdkmanager.