Skip to content

Instantly share code, notes, and snippets.

@agrcrobles
Forked from patrickhammond/android_instructions.md
Last active August 29, 2024 11:04
Show Gist options
  • Save agrcrobles/165ac477a9ee51198f4a870c723cd441 to your computer and use it in GitHub Desktop.
Save agrcrobles/165ac477a9ee51198f4a870c723cd441 to your computer and use it in GitHub Desktop.
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:

https://github.com/shyiko/jabba instead ?

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

From https://stackoverflow.com/questions/64312200/android-sdk-has-been-officially-discontinued-upstream

If you don't want the full android-studio development app (Intellij IDE, etc) and just want the new command line tools...

Per the discontinuation notice...

This SDK Tools package is deprecated and no longer receiving updates. Instead, please use the new command-line tools package.

A quick search reveals that in homebrew land, this new "command-line tools" package is called android-commandlinetools.

$ brew install android-commandlinetools

==> Installing Cask android-commandlinetools
==> Moving Generic Artifact 'cmdline-tools' to '/usr/local/share/android-command
==> Linking Binary 'avdmanager' to '/usr/local/bin/avdmanager'
==> Linking Binary 'lint' to '/usr/local/bin/lint'
==> Linking Binary 'retrace' to '/usr/local/bin/retrace'
==> Linking Binary 'screenshot2' to '/usr/local/bin/screenshot2'
==> Linking Binary 'sdkmanager' to '/usr/local/bin/sdkmanager'
==> Linking Binary 'apkanalyzer' to '/usr/local/bin/apkanalyzer'
🍺  android-commandlinetools was successfully installed!

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 remove android-sdk
==> Installing dependencies for gradle: openjdk
==> Installing gradle dependency: openjdk
==> Pouring openjdk--18.0.1.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/openjdk/18.0.1: 641 files, 307.7MB
==> Installing gradle
==> Pouring gradle--7.4.2.all.bottle.tar.gz
🍺  /usr/local/Cellar/gradle/7.4.2: 11,257 files, 267.8MB
==> Running `brew cleanup gradle`...

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

avdmanager list (find device skin id, lets use pixel 17)

List the device definitions available:

avdmanager list
...
---------
id: 11 or "Nexus 6P"
    Name: Nexus 6P
    OEM : Google
---------
...

create a virtual device based on device definition "Nexus 6P"

~avdmanager create avd --force --name Nexus6P --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64' --device "Nexus 6P"


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

Error: Package path is not valid. Valid system image paths are:ository... null

SDK preferred location

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

macbookpro@Macbooks-MacBook-Pro ~ %   which sdkmanager
/usr/local/bin/sdkmanager

macbookpro@Macbooks-MacBook-Pro ~ % sdkmanager --list

Install build tools and platform tools

The packages argument is an SDK-style path as shown with the --list command, wrapped in quotes (for example, "build-tools;30.0.2" or "platforms;android-28"). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.

For example, here's how to install the latest platform tools (which includes adb and fastboot) and the SDK tools for API level 28:

sdkmanager "platform-tools" "platforms;android-28"

Read terms and conditions

January 16, 2019
---------------------------------------
Accept? (y/N):

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"

or

export ANDROID_HOME="/usr/local/bin/sdkmanager"

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

echo export "PATH=/Users/macbookpro/Library/Android/sdk/platform-tools:$PATH" >> ~/.zshenv

Android NDK

TODO

Thanks!!!!

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

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

More helpfull Resources

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

Happy code!!

License

Opinions are my own

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
@eddsaura
Copy link

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!

@wanxe
Copy link

wanxe commented Mar 3, 2022

I would invite you a beer without hesitation, thanks!

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