Setup Android Development Environment on MacOS
Install Java
brew cask install java
You can use the following command to verify which version it will install.
brew cask info java
Install Android SDK
Goto Android Command Line Tools, Scroll down to the Command line tools only section:
Download Android Command Line Tools for Mac
Speed up the download process with the following command:
curl https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip \
-o ~/software/sdk-tools-darwin-4333796.zip
Unzip sdk-tools-darwin-4333796.zip to directory $HOME/Library/Android/sdk
Set PATH variable
export PATH=$HOME/Library/Android/sdk/tools/bin:$PATH
export PATH=$HOME/Library/Android/sdk/platform-tools:$PATH
Before using sdkmanager to download the desired version of SDK, slight modification need to made to the sdkmanager script to avoid NoClassDefFoundError, credit goes to Siu Ching Pong -Asuka Kenji
Find and replace the follow:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME”’
with:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Install platform-tools
Android SDK only install basic tools such as sdkmanager, apkanalyzer, monkeyrunner, but commands such as adb, systrace are not included, using sdkmanager to install latest version of platform-tools as follows:
sdkmanager "platform-tools" "platforms;android-28"
sdkmanager -- list to list installed and available packages
sdkmanager -- help for more
Installing adb
If you only need adb command, the easiest way to is Using Homebrew
brew cask install android-platform-tools
The command above will download platform tools from official website and the following binaries will be also installed:
==> Linking Binary 'dmtracedump' to '/usr/local/bin/dmtracedump'.
==> Linking Binary 'etc1tool' to '/usr/local/bin/etc1tool'.
==> Linking Binary 'fastboot' to '/usr/local/bin/fastboot'.
==> Linking Binary 'hprof-conv' to '/usr/local/bin/hprof-conv'.
==> Linking Binary 'mke2fs' to '/usr/local/bin/mke2fs'.
brismuth at stackoverflow provided other two options.
Install Android NDK
brew cask install android-ndk
This will install android ndk to /usr/local/Caskroom/android-ndk/18/android-ndk-r18/