Command Line Install of Android SDK [macOS]

Command Line Install of Android SDK [macOS]

Here's how to install the Android SDK and command line tools entirely from the command line.

Mostly follow the steps in this excellent blog with a few tweaks as follows.

How to setup Android SDK without Android Studio.
Easily setup Android SDK using Android CLI for React Native, Flutter etc.

Place in ~/Library/Android/sdk

Move and rename the unzipped cmdline-tools to this different location. This location is compatible with IntelliJ IDEA (confirmed) and Android Studio (unconfirmed):

mkdir -p ~/Library/Android/sdk/cmdline-tools
mv ~/Downloads/cmdline-tools ~/Library/Android/sdk/cmdline-tools/latest

sdkmanager --install

Here's a more recent set of essential packages to install.

sdkmanager --install "platform-tools" "build-tools;30.0.2"
sdkmanager --install "platforms;android-30" "ndk;21.4.7075529" 

sdkmanager --licenses

If a command-line Gradle build complains of licenses not being accepted, accept all licenses with this command:

yes | sdkmanager --licenses

Use Brew to Install Gradle and OpenJDK

brew install gradle # includes OpenJDK

Now you can execute gradle assembleDebug etc. at the command line.

Bonus: Ode to the Android Toolchain

O Android
Your projects are so not forward-compatible
Existing projects have been breaking on newer versions of the toolset
For 13+ years now
We developers are faced with two choices,
Each one worse than the other:
Update the toolset whenever possible
And fritter away our time to get things working again, or:
Wait until we have to update and spend most of a day on it
Shaking my head