Skip to content

Instantly share code, notes, and snippets.

@gretzky
Last active January 7, 2021 03:55
Show Gist options
  • Save gretzky/7f2bbd44eb32a16d0a1db3d66baf50cd to your computer and use it in GitHub Desktop.
Save gretzky/7f2bbd44eb32a16d0a1db3d66baf50cd to your computer and use it in GitHub Desktop.
Android development without Android studio (macOS)

Android Development without Android Studio

Note, most of my Android development is React Native based, so YMMV.

Prerequisites

  • Homebrew
  • Xcode (installed from App store)
  • Xcode command line tools (xcode-select --install)

Instructions

Install packages

brew install gradle
brew cask install adoptopenjdk8 adoptopenjdk8-jre intel-haxm android-sdk android-ndk

Set environment variables (in .zshrc, etc.)

export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"
export ANDROID_NDK_ROOT="/usr/local/share/android-ndk"
export PATH=$ANDROID_SDK_ROOT/emulator:$PATH:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/build-tools/28.0.3

Download packages

# add this empty file (macOS will complain that it doesnt exist)
touch ~/.android/repositories.cfg

# accept the sdkmanager licenses
yes | sdkmanager --licenses

# run updates
sdkmanager --update

# install packages
sdkmanager --install emulator
sdkmanager --install platform-tools
sdkmanager --install 'system-images;android-29;google_apis_playstore;x86_64'
sdkmanager --install 'build-tools;29.0.2' # pick your version, this is what's used in react native >=0.60
sdkmanager --install 'platforms;android-29'

Working with emulators

# show all potential emulators
avdmanager list

# create an emulator
avdmanager create avd -f -n EMU_NAME -d ID_NUMBER -k 'system-images;android-29;google_apis_playstore;x86_64'

# view all created avds
avdmanager list avd

# run an emulator
emulator @EMU_NAME

# delete an avd
avdmanager delete avd -n EMU_NAME

Protip: enable physical keyboard on all emulators: for f in ~/.android/avd/*.avd/config.ini; do echo 'hw.keyboard=yes' >> "$f"; done

@lanzorg
Copy link

lanzorg commented Jan 7, 2021

Android-sdk is deprecated, you should now use the command line tools package.
Strangely, I can't find any homebrew package for it.
Windows users are more lucky, there is a scoop package available.
https://github.com/ScoopInstaller/Main/blob/master/bucket/android-clt.json

You can check my archlinux post installation script here to understand the new command line tools.
https://github.com/lanzorg/anarch/blob/master/anarch.sh#L156

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