Skip to content

Instantly share code, notes, and snippets.

@patrickhammond
Last active October 13, 2024 21:08
Show Gist options
  • Save patrickhammond/4ddbe49a67e5eb1b9c03 to your computer and use it in GitHub Desktop.
Save patrickhammond/4ddbe49a67e5eb1b9c03 to your computer and use it in GitHub Desktop.
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Make sure the doctor is happy (do what it tells you):

brew doctor

Use Homebrew to install Android dev tools:

brew install ant
brew install maven
brew install gradle
brew install android-sdk
brew install android-ndk

Install all of the Android SDK components (you will be prompted to agree to license info and then this will take a while to run):

android update sdk --no-ui

Install HAXM for blazing fast emulators. Check out the "Configuring VM Acceleration on Mac" section here: http://developer.android.com/tools/devices/emulator.html

Update your environment variables:

export ANT_HOME=/usr/local/opt/ant
export MAVEN_HOME=/usr/local/opt/maven
export GRADLE_HOME=/usr/local/opt/gradle
export ANDROID_HOME=/usr/local/opt/android-sdk
export ANDROID_NDK_HOME=/usr/local/opt/android-ndk

Update your paths (bonus points to a better solution to the hardcoded build tools version):

export PATH=$ANT_HOME/bin:$PATH
export PATH=$MAVEN_HOME/bin:$PATH
export PATH=$GRADLE_HOME/bin:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/build-tools/19.1.0:$PATH

Periodically run these commands again to ensure you're staying up to date:

brew update
android update sdk --no-ui
  • Note: It looks like there might be an issue with brew update and the android-sdk formula.

Install Eclipse, IntelliJ, Android Studio, or your other favorite IDE.

If everything goes smoothly on a moderate network connection you can expect this process to take 2-4 hours.

@PManager1
Copy link

I get this error
image

@gaurav21
Copy link

@jpca999 use
brew install caskroom/cask/android-ndk

@hendricius
Copy link

hendricius commented Jul 24, 2017

or just:

brew cask install android-sdk
brew cask install android-ndk

@bitspace
Copy link

Having the ANT_HOME environment variable set breaks ant.

With it set:
% ant --execdebug
exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH" "-lib" "/usr/local/share/ant" Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

Without it set:
% ant --execdebug
exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH"
Buildfile: build.xml does not exist!
Build failed

Ref. this issue.

@agrcrobles
Copy link

agrcrobles commented Nov 28, 2017

Update your environment variables

From http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac:

https://apple.stackexchange.com/questions/106778/how-do-i-set-environment-variables-on-os-x

android-28 / android-30

sdk can be installed on /Library/Android/sdk or /usr/local/ to be sure check it by

which sdkmanager

Export ANDROID_HOME

export ANDROID_HOME=$HOME/Library/Android/sdk

or

export ANDROID_HOME="/usr/local/share/android-sdk"

Both are valid locations for the android sdk from what I am aware of :)

android-28 / android-30

Copy paste, It's a good idea double check your paths anyways.

export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

see

@mrded
Copy link

mrded commented Mar 11, 2018

Update:

Use Homebrew to install Android dev tools:

brew cask install android-sdk
brew cask install android-ndk

Update your environment variables:

export ANDROID_NDK_HOME=/usr/local/share/android-ndk
export ANDROID_SDK_ROOT=/usr/local/share/android-sdk

Install all of the Android SDK components:

sdkmanager --update

@LeaveNhA
Copy link

Thanks @mrded !
Almost one-line offer.

@amityweb
Copy link

amityweb commented May 21, 2018

Can you update the instructions save reading all the threads, its the following for me:
brew cask install android-sdk
brew cask install android-ndk

@mhcameron
Copy link

I had so much trouble getting the android sdk and java sdk working with my Pixel, running through multiple iterations of Android Studio setup and different versions of Java. I am on OSX

I finally started over and settled on the following:
java version "1.8.0_171" (JDK 8)

This brew cask was the only thing I could get my Pixel working with:
brew cask install android-studio

react-native-cli: 2.0.1

Thanks to the makers of that cask.

@molcik
Copy link

molcik commented Jul 11, 2018

Do you want to avoid struggle with this setup? Read this tutorial

@ngryman
Copy link

ngryman commented Jul 23, 2018

@molcik Just curious, where did you struggle exactly? @mrded's update is pretty straightforward and worked for me ¯_(ツ)_/¯

@lahdekorpi
Copy link

@molcik that website is just absolute spam. It only provides an alternative "solution" of installing Android Studio. And then links to this very gist.
Should probably be reported as spam...

@djangofan
Copy link

Of course, brew cask install java will install and help you maintain the JDK.

or asdf plugin-add java && asdf install java oracle-8.191 && asdf global java oracle-8.191

@X901
Copy link

X901 commented Jan 3, 2019

Thank you so much , Finally working with showing this error Cannot find AVD system path. Please define ANDROID_SDK_ROOT

@MuntashirAkon
Copy link

android-ndk is no longer available.

@andrewhavens
Copy link

andrewhavens commented May 1, 2019

2019 Update:

Some packages have been removed or changed (such as java, android-ndk, etc). This is what worked for me:

brew cask install adoptopenjdk8
brew cask install android-sdk

echo "export ANDROID_HOME=/usr/local/share/android-sdk" >> ~/.bash_profile
source ~/.bash_profile

touch ~/.android/repositories.cfg
sdkmanager --update
sdkmanager "platform-tools" "platforms;android-28"

The sdkmanager had a problem when ~/.android/repositories.cfg didn't exist, but by simply creating the file, it solved the problem.

@romenigld
Copy link

romenigld commented May 11, 2019

Install with:
brew cask install android-studio

@8secz-johndpope
Copy link

brew cask install android-studio

@justmara
Copy link

brew install android-studio --cask since new brew

@ThePredators
Copy link

For People who make both Android, iOS Apps i made a crazy doc here

Enjoy !

@phamsarah
Copy link

Note, adoptopendk8 has been officially discontinued, it may stop working in recent versions of MacOS.
Temurin is the official successor:

brew install --cask temurin8

@ThePredators
Copy link

I advice you guy to use Jabba instead of anything else ! https://github.com/shyiko/jabba

@siathalysedI
Copy link

It's better to use sdkman to instal any jdk version (temurin or any other), ant, gradle and maven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment