Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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.

@sako0405

This comment has been minimized.

Show comment Hide comment
@sako0405

sako0405 Nov 13, 2014

hello,
Homwbrew install url has been changed to this.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

hello,
Homwbrew install url has been changed to this.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

@Dorian

This comment has been minimized.

Show comment Hide comment
@Dorian

Dorian Jul 23, 2015

You can use brew cask install intel-haxm to install Intel HAXM (I just fixed the cask file, it needs to be merged to master).

Dorian commented Jul 23, 2015

You can use brew cask install intel-haxm to install Intel HAXM (I just fixed the cask file, it needs to be merged to master).

@Dorian

This comment has been minimized.

Show comment Hide comment
@Dorian

Dorian Jul 24, 2015

Same for android studio: brew cask install android-studio.

Dorian commented Jul 24, 2015

Same for android studio: brew cask install android-studio.

@skizzo

This comment has been minimized.

Show comment Hide comment
@skizzo

skizzo Oct 19, 2015

Hi,
tried to install the Android SDK via android update sdk --no-ui but it failed cause I ran out of disk space. I can't find the location where the files have been downloaded to, anybody knows where it can be found? Need to delete this since it fills up my hard drive.. Thanks

skizzo commented Oct 19, 2015

Hi,
tried to install the Android SDK via android update sdk --no-ui but it failed cause I ran out of disk space. I can't find the location where the files have been downloaded to, anybody knows where it can be found? Need to delete this since it fills up my hard drive.. Thanks

@kim0

This comment has been minimized.

Show comment Hide comment
@kim0

kim0 Jan 3, 2016

For the build-tools embedded version problem, try

export PATH=$ANDROID_HOME/build-tools/$(ls -tr $ANDROID_HOME/build-tools/ | tail -1):$PATH

kim0 commented Jan 3, 2016

For the build-tools embedded version problem, try

export PATH=$ANDROID_HOME/build-tools/$(ls -tr $ANDROID_HOME/build-tools/ | tail -1):$PATH
@paulxtiseo

This comment has been minimized.

Show comment Hide comment
@paulxtiseo

paulxtiseo Feb 2, 2016

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

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

@cricket007

This comment has been minimized.

Show comment Hide comment
@cricket007

cricket007 Mar 20, 2016

If you want the latest version of the build-tools and not the most recently installed try this

export PATH=$ANDROID_HOME/build-tools/$(ls $ANDROID_HOME/build-tools | sort | tail -1):$PATH

If you want the latest version of the build-tools and not the most recently installed try this

export PATH=$ANDROID_HOME/build-tools/$(ls $ANDROID_HOME/build-tools | sort | tail -1):$PATH
@gkimpson

This comment has been minimized.

Show comment Hide comment
@gkimpson

gkimpson Apr 19, 2016

How would you setup environment variables if using zsh shell rather than the default one?

How would you setup environment variables if using zsh shell rather than the default one?

@ciscoo

This comment has been minimized.

Show comment Hide comment
@ciscoo

ciscoo Aug 10, 2016

@gkimpson edit ~/.zshrc like you would .bashrc

ciscoo commented Aug 10, 2016

@gkimpson edit ~/.zshrc like you would .bashrc

@xjones

This comment has been minimized.

Show comment Hide comment
@xjones

xjones Feb 27, 2017

ANT_HOME should be set as:

export ANT_HOME=/usr/local/opt/ant/libexec

xjones commented Feb 27, 2017

ANT_HOME should be set as:

export ANT_HOME=/usr/local/opt/ant/libexec

@tokra

This comment has been minimized.

Show comment Hide comment
@tokra

tokra Apr 18, 2017

Hi, android-sdk is no more available in brew install but brew cask install android-sdk

tokra commented Apr 18, 2017

Hi, android-sdk is no more available in brew install but brew cask install android-sdk

@gangachris

This comment has been minimized.

Show comment Hide comment
@gangachris

gangachris Apr 21, 2017

brew cask install android-sdk brings in the version without the android command. You now have to use sdkmanager

brew cask install android-sdk brings in the version without the android command. You now have to use sdkmanager

@sarojrout

This comment has been minimized.

Show comment Hide comment
@sarojrout

sarojrout Apr 28, 2017

my android_sdk path is set to /usr/local/Caskroom/android-sdk/25.2.3 after i did brew cask install android_sdk
But when i try to create android app using native CLI, it gives me an error
The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android

my android_sdk path is set to /usr/local/Caskroom/android-sdk/25.2.3 after i did brew cask install android_sdk
But when i try to create android app using native CLI, it gives me an error
The ANDROID_HOME environment variable points to incorrect directory. You will not be able to perform any build-related operations for Android

@andrewvmail

This comment has been minimized.

Show comment Hide comment
@andrewvmail

andrewvmail May 9, 2017

For anyone with NPE error and a stacktrace related to NDK i had to do this to fix.
Remove export ANDROID_NDK_HOME=/usr/local/opt/android-ndk

https://issuetracker.google.com/issues/37126455

For anyone with NPE error and a stacktrace related to NDK i had to do this to fix.
Remove export ANDROID_NDK_HOME=/usr/local/opt/android-ndk

https://issuetracker.google.com/issues/37126455

@hprobotic

This comment has been minimized.

Show comment Hide comment
@hprobotic

hprobotic Jun 10, 2017

Use sdkmanager --update instead android sdk update

Use sdkmanager --update instead android sdk update

@cesar-oyarzun-m

This comment has been minimized.

Show comment Hide comment
@cesar-oyarzun-m

cesar-oyarzun-m Jun 12, 2017

@hprobotic I'm trying to run the emulator but I get android sdk not found, has anyone see same problem. I'm using brew cask install android-sdk and my configuration is this

export ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export ANDROID_HOME=/usr/local/share/android-sdk
export ANDROID_NDK_HOME=/usr/local/opt/android-ndk
export PATH="$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/tools:$PATH"
sdkmanager "system-images;android-25;google_apis;armeabi-v7a"
sdkmanager --update 
sdkmanager  --list
#avdmanager create avd -n Nexus6P -k "system-images;android-23;google_apis;x86_64" -b google_apis/x86_64 -c 100M -d 7 -f
avdmanager create avd -n test -k "system-images;android-25;google_apis;armeabi-v7a" -b armeabi-v7a -c 100M -d 7 -f
avdmanager list avd
cd $(dirname $(which emulator)) && ./emulator @test -no-audio -no-window -verbose

I get error

emulator: qemu backend: argv[00] = "../emulator/qemu/darwin-x86_64/qemu-system-armel"
emulator: qemu backend: argv[01] = "@test"
emulator: qemu backend: argv[02] = "-no-audio"
emulator: qemu backend: argv[03] = "-no-window"
emulator: qemu backend: argv[04] = "-verbose"
emulator: Concatenated backend parameters:
 ../emulator/qemu/darwin-x86_64/qemu-system-armel @test -no-audio -no-window -verbose
emulator: ERROR: can't find SDK installation directory
emulator: could not find virtual device named 'test'

cesar-oyarzun-m commented Jun 12, 2017

@hprobotic I'm trying to run the emulator but I get android sdk not found, has anyone see same problem. I'm using brew cask install android-sdk and my configuration is this

export ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export ANDROID_HOME=/usr/local/share/android-sdk
export ANDROID_NDK_HOME=/usr/local/opt/android-ndk
export PATH="$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/tools:$PATH"
sdkmanager "system-images;android-25;google_apis;armeabi-v7a"
sdkmanager --update 
sdkmanager  --list
#avdmanager create avd -n Nexus6P -k "system-images;android-23;google_apis;x86_64" -b google_apis/x86_64 -c 100M -d 7 -f
avdmanager create avd -n test -k "system-images;android-25;google_apis;armeabi-v7a" -b armeabi-v7a -c 100M -d 7 -f
avdmanager list avd
cd $(dirname $(which emulator)) && ./emulator @test -no-audio -no-window -verbose

I get error

emulator: qemu backend: argv[00] = "../emulator/qemu/darwin-x86_64/qemu-system-armel"
emulator: qemu backend: argv[01] = "@test"
emulator: qemu backend: argv[02] = "-no-audio"
emulator: qemu backend: argv[03] = "-no-window"
emulator: qemu backend: argv[04] = "-verbose"
emulator: Concatenated backend parameters:
 ../emulator/qemu/darwin-x86_64/qemu-system-armel @test -no-audio -no-window -verbose
emulator: ERROR: can't find SDK installation directory
emulator: could not find virtual device named 'test'
@jpca999

This comment has been minimized.

Show comment Hide comment
@jpca999

jpca999 Jul 17, 2017

I get this error
image

jpca999 commented Jul 17, 2017

I get this error
image

@gaurav21

This comment has been minimized.

Show comment Hide comment
@gaurav21

gaurav21 Jul 18, 2017

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

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

@hendricius

This comment has been minimized.

Show comment Hide comment
@hendricius

hendricius Jul 24, 2017

or just:

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

hendricius commented Jul 24, 2017

or just:

brew cask install android-sdk
brew cask install android-ndk
@bitspace

This comment has been minimized.

Show comment Hide comment
@bitspace

bitspace Jul 26, 2017

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.

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

This comment has been minimized.

Show comment Hide comment
@agrcrobles

agrcrobles Nov 28, 2017

Updated instructions using build tools 23: https://gist.github.com/agrcrobles/165ac477a9ee51198f4a870c723cd441

@mrded

This comment has been minimized.

Show comment Hide comment
@mrded

mrded 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

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

This comment has been minimized.

Show comment Hide comment
@LeaveNhA

LeaveNhA Mar 15, 2018

Thanks @mrded !
Almost one-line offer.

Thanks @mrded !
Almost one-line offer.

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