Skip to content

Instantly share code, notes, and snippets.

@bluenex
Last active June 7, 2024 09:29
Show Gist options
  • Save bluenex/96a31acfebea4ad7b1b927b7125e4569 to your computer and use it in GitHub Desktop.
Save bluenex/96a31acfebea4ad7b1b927b7125e4569 to your computer and use it in GitHub Desktop.
Setting up Android dev environment without Android Studio via brew on Mac OSX [Android Virtual Device (AVD) included]

Prerequisites

  • Homebrew

Android SDK

Install JAVA

First, install JAVA. Note that Android SDK is not yet supported JAVA 10, so install JAVA 8:

$ brew tap caskroom/versions
$ brew cask install java8

Export JDK path for Android Studio in ~/.bash_profile or ~/.zshrc:

export STUDIO_JDK="$(/usr/libexec/java_home -v1.8)"

Install Android SDK/NDK

Then install fundamental cores for Android dev:

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

Export $ANDROID_HOME:

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

Install packages

Start from build tools and main packages:

sdkmanager "platforms;android-27"
sdkmanager "build-tools;27.0.3"
sdkmanager "extras;android;m2repository"
sdkmanager "extras;google;m2repository"
sdkmanager "sources;android-27"

Then accept licenses:

sdkmanager --licenses

Android virtual device (AVD)

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

First update sdkmanager

$ sdkmanager --update

List device

In this case want to use Google Pixel as base device. Remember the id 17.

$ avdmanager list | grep 'pixel'                                                                                           Device: pixel (Google)
  Device: pixel (Google)
id: 17 or "pixel"
id: 18 or "pixel_c"
id: 19 or "pixel_xl"

List system-images

$ sdkmanager --list | grep system-images

Choose the one you like to go with and install it:

$ sdkmanager 'system-images;android-25;google_apis;x86_64'

There is also image with playstore version, you can get it from:

$ sdkmanager --list | grep "system-images.*playstore"
  system-images;android-25;google_apis_playstore;x86  | 9    | Google Play Intel x86 Atom System Image 

$ sdkmanager 'system-images;android-25;google_apis_playstore;x86'

Create AVD

  • -n : name of the virtual device.
  • -k : package to use, installed in previous step.
  • -d : device id for hardware profile.
$ avdmanager create avd -n Pixel -k 'system-images;android-25;google_apis;x86_64' -d 17

List AVD

$ avdmanager list avd
    Name: Pixel
  Device: pixel (Google)
    Path: /Users/tulakann/.android/avd/Pixel.avd
  Target: Google APIs (Google Inc.)
          Based on: Android API 25 Tag/ABI: google_apis/x86_64

Delete AVD

$ avdmanager delete avd -n Pixel

Emulator

src: https://developer.android.com/studio/run/emulator-commandline

List available AVD

$ emulator -list-avds

Run without options

emulator -avd avd_name

Or

emulator @avd_name

Add keyboard forwarding

By default hw.keyboard is not set in config.ini of AVD. To enable hardware keyboard to send to emulator, run commands below:

for file in ~/.android/avd/*avd; do 
  if cat $file/config.ini | grep "hw.keyboard=yes" > /dev/null; then 
    echo "✔ hw.keyboard is already added to $(basename $file)"
  else 
    echo "hw.keyboard=yes" >> $file/config.ini
    echo "✔ hw.keyboard=yes is added to $(basename $file)"
  fi
done

These commands set hw.keyboard for all AVD available in ~/.android/avd.

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