Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup Android SDK on OSX with and without the android studio

Hi, I am a fork from https://gist.github.com/patrickhammond/4ddbe49a67e5eb1b9c03.

A high level overview for what I need to do to get most of an Android environment setup and maintained on OSX higher Catalina and Big Sur with and without Android Studio been installed.

Considering the SDK is installed under /Users/<your_user>/Library/Android/sdk folder which is the Android Studio preferred SDK location, but it works fine under /usr/local/share/android-sdk as well, which is a location pretty much used on CI mostly.

Prerequisites:

See for brew, python3 and NodeJS on nvm see gist https://gist.github.com/agrcrobles/3d945b165871c355b6f169c317958e3e

Java 14

Open JDK 14 works fine with gradle 6.x

Preferred: To install the JDKs 8 ( LTS ) AdoptOpenJDK:

# brew tap adoptopenjdk/openjdk via cask

brew install adoptopenjdk/openjdk/adoptopenjdk8

Alternative: Do not follow this step if followed the step before

brew install java8

SDK Manager

Be sure JAVA_HOME is exported on your bash profile or zshrc depending the shell in usage.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

See https://developer.android.com/studio/intro/update#sdk-manager

Without Android Studio

Or try Command line tools | Android

Use Command line tools or SDK Manager

Quick reminder: Have as many build tools as you want, have a single one platform tool with backwards compatibility :=)

Download and Install Command line tools for mac ( not the android studio unless I need it )

https://developer.android.com/studio#cmdline-tools

https://developer.android.com/studio/command-line

https://developer.android.com/studio/command-line/sdkmanager

Use Homebrew to install Android dev tools: Note that Java8 is tricky since licence changed: https://stackoverflow.com/questions/24342886/how-to-install-java-8-on-mac

brew install gradle
brew install android-sdk

Optional

brew install ant
brew install maven
brew cask install android-ndk

https://developer.android.com/studio#cmdline-tools

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):

If you need to have openjdk first in your PATH run: echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk you may need to set: export CPPFLAGS="-I/usr/local/opt/openjdk/include"

QEMU

Be sure Intel Hardware Accelerated Execution Manager (HAXM) is properly installed.

HAXM is a cross-platform hardware-assisted virtualization engine (hypervisor), be sure HAXM is properly installed.

See https://developer.android.com/studio/run/emulator-acceleration

Create and run virtual devices? Nga copied from https://gist.github.com/gasolin/9300f5f9276b2df884c80da3e2c54ffc

avdmanager list (find device skin id, lets use pixel 17)
avdmanager create avd -f -n test -d 17 -k 'system-images;android-29;google_apis_playstore;x86_64'
avdmanager list avd (or emulator -list-avds)

/usr/local/share/android-sdk/emulator/emulator -avd test

SDK preferred location

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"

or

export ANDROID_HOME="$HOME/Library/Android/sdk"

All locations are valid ones from what I am aware of :)

Suggested: You will have to add the ANDROID_HOME to the profile configuration settings either on .zshrc, .bashrc or .bash_profile

If emulator doesn't run, i am here to remind you to provide access into System Preferences - Security & Privacy

Android NDK

TODO

adb cheatsheet

https://gist.github.com/HugoMatilla/f92682b06068b06a6f2a

Creating an android AVD

https://stackoverflow.com/a/44172716/6716408

More helpfull Resources

https://glacion.com/2019/04/06/AVD.html

Happy code

License

Unlicensed, opiniated and unofficial

android-28

touch ~/.android/repositories.cfg
yes | sdkmanager --licenses
sdkmanager "platform-tools" "platforms;android-28"
sdkmanager --no_https --install 'build-tools;28'
sdkmanager --no_https --install emulator
sdkmanager --list

android-29

touch ~/.android/repositories.cfg
yes | sdkmanager --licenses
sdkmanager --update
sdkmanager --no_https --install emulator
sdkmanager --no_https --install platform-tools
sdkmanager --no_https --install 'system-images;android-29;google_apis_playstore;x86_64'
sdkmanager --no_https --install 'extras;intel;Hardware_Accelerated_Execution_Manager'
sdkmanager --no_https --install 'build-tools;29.0.2'
sdkmanager --no_https --install 'platforms;android-29'
sdkmanager --list

android-23

touch ~/.android/repositories.cfg
sdkmanager "platform-tools" "platforms;android-23"
sdkmanager "build-tools;23.0.1"

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

brew cask install intel-haxm // this might not work on high sierra.

Edit: You can download the dmg and install manually from Intel's site

Install emulators? Nga copied from https://gist.github.com/gasolin/9300f5f9276b2df884c80da3e2c54ffc

sdkmanager --no_https --install emulator
sdkmanager --no_https --install platform-tools
sdkmanager --no_https --install 'system-images;android-29;google_apis_playstore;x86_64'
sdkmanager --no_https --install 'extras;intel;Hardware_Accelerated_Execution_Manager'
sdkmanager --update
sdkmanager --list

Update your environment variables:

https://stackoverflow.com/questions/65711364/how-to-open-the-avd-manager-on-osx-from-iterm2/65711365#65711365

android-28 / android-30

To 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

android-23

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

Optional: Build tool version specific export

PATH for build-tools/23.0.1

export PATH=$ANDROID_HOME/build-tools/23.0.1:$PATH

PATH for build-tools/28.0.3

export PATH=$ANDROID_HOME/build-tools/28.0.3:$PATH
@agrcrobles

This comment has been minimized.

Copy link
Owner Author

@agrcrobles agrcrobles commented Nov 28, 2017


➜  MyApp git:(master) ✗ gradle --version

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          13.0.2 (Oracle Corporation 13.0.2+8)
OS:           Mac OS X 10.15.5 x86_64

➜  MyApp git:(master) ✗ adb devices
List of devices attached
R58M92DCXFR	device

Output For android-28

$ sdkmanager --list

  Path                                                  | Version | Description                                | Location
  -------                                               | ------- | -------                                    | -------
  emulator                                              | 30.0.12 | Android Emulator                           | emulator/
  patcher;v4                                            | 1       | SDK Patch Applier v4                       | patcher/v4/
  platforms;android-28                                  | 6       | Android SDK Platform 28                    | platforms/android-28/
  system-images;android-28;google_apis_playstore;x86_64 | 8       | Google Play Intel x86 Atom_64 System Image | system-images/android-28/google_apis_playstore/x86_64/
  tools                                                 | 26.1.1  | Android SDK Tools 26.1.1                   | tools/


Output For android-26

$ sdkmanager --list

  Path               | Version | Description                    | Location           
  -------            | ------- | -------                        | -------            
  build-tools;26.0.2 | 26.0.2  | Android SDK Build-Tools 26.0.2 | build-tools/26.0.2/
  emulator           | 26.1.4  | Android Emulator               | emulator/          
  patcher;v4         | 1       | SDK Patch Applier v4           | patcher/v4/        
  platform-tools     | 26.0.2  | Android SDK Platform-Tools     | platform-tools/    
  tools              | 26.1.1  | Android SDK Tools              | tools/             


@tonejac

This comment has been minimized.

Copy link

@tonejac tonejac commented Dec 20, 2017

Is that correct with the line:
sdkmanager --install "build-tools;23.0.1"

Couldn't get that one to work. Says "Warning: Unknown argument --install".

@tonejac

This comment has been minimized.

Copy link

@tonejac tonejac commented Dec 21, 2017

I took out the --install flag and it worked great.

Thanks for putting this together. Solid info!!

@schutzsmith

This comment has been minimized.

Copy link

@schutzsmith schutzsmith commented Dec 23, 2017

Same here, removing the --install flag worked like a charm.

Thanks for the updated instructions!

@agrcrobles

This comment has been minimized.

Copy link
Owner Author

@agrcrobles agrcrobles commented Dec 27, 2017

yea updated, thanks for the feedback!!

@bramus

This comment has been minimized.

Copy link

@bramus bramus commented Jan 5, 2018

When starting fresh off, you'll also need to install Java. Note that version 9 won't work, so you'll have to specifically target version 8:

brew cask install caskroom/versions/java8
@AceLondon

This comment has been minimized.

Copy link

@AceLondon AceLondon commented Jan 8, 2018

Just putting it out there but HAXM install does not support the newest version of macOS - I'm currently on 10.13.2:

==> Standard Output of failed command: HAXM silent installation only supports macOS from 10.8 to 10.12 !

Thanks for the instructions! Beautifully curated!

@nitin7dc

This comment has been minimized.

Copy link

@nitin7dc nitin7dc commented Jan 12, 2018

thanks 👍

@vsviridov

This comment has been minimized.

Copy link

@vsviridov vsviridov commented Jan 31, 2018

Java9 Workaround (put in the .profile or similar)

export SDKMANAGER_OPTS="-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee"
@stevestock

This comment has been minimized.

Copy link

@stevestock stevestock commented Feb 3, 2018

brew cask install android-sdkautomatically installs java 8
see the android-sdk cask

EDIT: never mind, i misunderstood, brew cask only states the dependency, doesn't automatically install it

@mbunge

This comment has been minimized.

Copy link

@mbunge mbunge commented Feb 13, 2018

I ended up uninstalling JDK9 and installing Java SE Development Kit 8u144. Hope this helps. I also need to android-ndk and android-sdk and follow these stepps

brew cask uninstall android-ndk # Only of installed and ran in to error!
brew cask uninstall android-sdk # Only of installed and ran in to error!
brew cask uninstall java # uninstall java9
brew tap caskroom/versions
brew cask install java8
touch ~/.android/repositories.cfg # without this file, error will occur on next step
brew cask install android-sdk
@Cassidamius

This comment has been minimized.

Copy link

@Cassidamius Cassidamius commented Feb 22, 2018

Thanks for the instructions! As @AceLondon mentioned above, there's a problem on High Sierra (macOS version 10.13.x).
brew cask install intel-haxm doesn't work
==> Verifying checksum for Cask intel-haxm ==> Installing Cask intel-haxm ==> Running installer script 'silent_install.sh' **==> HAXM silent installation only supports macOS from 10.8 to 10.12 !** ==> Purging files for version 6.2.1,a0:49 of Cask intel-haxm Error: Command failed to execute!

You can download the dmg and install manually from Intel's site:
https://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-mac-os-x

@emanueleDiVizio

This comment has been minimized.

Copy link

@emanueleDiVizio emanueleDiVizio commented Jul 9, 2018

Quick update, ruby command to install homebrew doesn't seem to be working. Here's the command from homebrew website.

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

@jasonnmark

This comment has been minimized.

Copy link

@jasonnmark jasonnmark commented Jan 27, 2019

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

@andrewhavens

This comment has been minimized.

Copy link

@andrewhavens 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.

@hroland

This comment has been minimized.

Copy link

@hroland hroland commented Jul 16, 2019

echo "export ANT_HOME=/usr/local/opt/ant" >> ~/.bash_profile
echo "export MAVEN_HOME=/usr/local/opt/maven" >> ~/.bash_profile
echo "export GRADLE_HOME=/usr/local/opt/gradle" >> ~/.bash_profile
echo "export ANDROID_HOME=/usr/local/share/android-sdk" >> ~/.bash_profile
echo "export ANDROID_NDK_HOME=/usr/local/share/android-ndk" >> ~/.bash_profile
echo "export INTEL_HAXM_HOME=/usr/local/Caskroom/intel-haxm" >> ~/.bash_profile
@gasolin

This comment has been minimized.

Copy link

@gasolin gasolin commented Jul 18, 2019

need install jdk8 via

brew cask install adoptopenjdk/openjdk/adoptopenjdk8

instead of

brew cask install adoptopenjdk8

Here's a 2019 updated version https://gist.github.com/gasolin/9300f5f9276b2df884c80da3e2c54ffc

@cemo

This comment has been minimized.

Copy link

@cemo cemo commented Oct 21, 2019

@sairajasrikolluru

This comment has been minimized.

Copy link

@sairajasrikolluru sairajasrikolluru commented Dec 24, 2019

bin/sdkmanager from commandline throws below error -

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)

@d-koppenhagen

This comment has been minimized.

Copy link

@d-koppenhagen d-koppenhagen commented Jun 19, 2020

This can ba a problem when using a newer JAVA Version. You can fix this by:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
@tdrkDev

This comment has been minimized.

Copy link

@tdrkDev tdrkDev commented Jun 21, 2020

brew tap caskroom/cask is not needed now
First brew cask command is downloading cask repository

@eddsaura

This comment has been minimized.

Copy link

@eddsaura eddsaura commented Nov 26, 2020

I did so many things already that I don't know where am I.

When I try to run cordova run android --device I get the No installed build tools found. Install blablabla...

How is the final version and how can i clean all this mess? 😆

Thanks!

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