Keywords: macOS | ANDROID_HOME | Environment_Variable_Configuration
Abstract: This article provides a detailed guide on configuring the ANDROID_HOME environment variable in macOS systems, covering SDK path identification for different installation methods, environment variable configuration techniques, PATH variable updates, and verification procedures. Through concrete terminal command examples and in-depth technical analysis, it helps developers resolve Android development toolchain configuration issues and avoid common environment setup errors.
Analysis of Android SDK Installation Paths
Before setting the ANDROID_HOME environment variable on macOS, it is essential to determine the exact installation location of the Android SDK. The default paths vary significantly depending on the installation method employed.
When downloading the SDK directly from the official website and manually extracting it to the Applications folder, the typical installation path is /Applications/ADT/sdk. This installation approach was common in early Android development environments and requires manual management of SDK versions and components.
If using the Homebrew package manager for installation, executing brew cask install android-sdk places the SDK in the /usr/local/Caskroom/android-sdk/{SDK_VERSION_NUMBER} directory. The Homebrew method offers version management convenience but requires proper configuration of Caskroom directory access permissions.
For automatic installation through Android Studio, the SDK defaults to /Users/{USERNAME}/Library/Android/sdk. This is currently the recommended installation approach, as Android Studio automatically manages SDK versions and dependencies, ensuring development environment consistency.
Environment Variable Configuration Methods
After identifying the SDK installation path, environment variables must be configured via the terminal. Temporary setup can be achieved using the export command: export ANDROID_HOME=/Applications/ADT/sdk. This method is valid only for the current terminal session and is suitable for temporary testing and verification.
For permanent configuration, shell configuration files must be edited. Bash users should open the ~/.bash_profile file with a text editor: nano ~/.bash_profile. Add the following content at the end of the file:
export ANDROID_HOME=/Applications/ADT/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-toolsThis configuration ensures the ANDROID_HOME variable is automatically loaded with each terminal startup, while simultaneously adding the SDK tool directories to the system PATH, enabling direct invocation of command-line tools like adb.
Configuration Verification and Troubleshooting
After completing the configuration, verification of proper environment variable setup is necessary. First, reload the configuration file using source ~/.bash_profile, then check the variable value with echo $ANDROID_HOME. Correct output should display the complete SDK path.
In practical development, common errors include path spelling mistakes, configuration files not loading correctly, and shell type mismatches. For instance, if the user employs zsh instead of bash, the ~/.zshrc file must be edited instead of ~/.bash_profile. The current shell type can be confirmed using the echo $0 command.
When using automation tools like Appium, incorrect ANDROID_HOME configuration leads to errors such as "Could not find adb". In such cases, ensure environment variables are available in GUI applications, as some applications may not inherit terminal environment variables.
Best Practices for Path Configuration
When configuring the PATH variable, the recommended approach is to prepend SDK tool directories: export PATH=$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH. This configuration ensures SDK-provided tools take precedence over tools with the same name in other system locations, preventing version conflict issues.
For team development projects, it is advisable to clearly document SDK path configuration requirements in project documentation or use version control to manage configuration files. This ensures consistent environment configuration across all development team members, reducing problems caused by environmental differences.
Regularly checking for SDK updates is also crucial. When upgrading SDK versions, corresponding updates to the ANDROID_HOME path are necessary, particularly with Homebrew installations where version numbers change. It is recommended to backup existing configurations before upgrades to ensure smooth transition processes.