androidmacoscommand-line-interfacehomebrewemulation

How to install Android emulator on macOS from CLI?


I'm trying to install the Android emulator tool from CLI on macOS 12.

So first I installed openjdk.

$ brew install openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/22.0.2
####################################################################################################################################################################################### 100.0%
==> Fetching openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:84795b272691e9ee02b9a0bb9fba35552c1ae8d3b977be2468dc71e57aa4e42f
Already downloaded: /Users/sebastien/Library/Caches/Homebrew/downloads/d77dda9a4f3951018aa3f9bb83beae31f635ebac5ba939d25d7278da1345ca95--openjdk--22.0.2.monterey.bottle.tar.gz
==> Pouring openjdk--22.0.2.monterey.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

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

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> Summary
🍺  /usr/local/Cellar/openjdk/22.0.2: 602 files, 330MB
Warning: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!

Then I added openjdk to the path :

$ which java
/usr/local/opt/openjdk/bin/java
$ 

Finally, I installed android-commandlinetools :

$ brew install android-commandlinetools
==> Caveats
Default Android SDK root is /usr/local/share/android-commandlinetools

android-commandlinetools requires Java. You can install the latest version with:
  brew install --cask temurin

==> Downloading https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip
##################################################################################################################################### 100.0%
==> Installing Cask android-commandlinetools
==> Moving Generic Artifact 'cmdline-tools' to '/usr/local/share/android-commandlinetools/cmdline-tools/latest'
==> 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 'sdkmanager' to '/usr/local/bin/sdkmanager'
==> Linking Binary 'apkanalyzer' to '/usr/local/bin/apkanalyzer'
==> Linking Binary 'screenshot2' to '/usr/local/bin/screenshot2'
🍺  android-commandlinetools was successfully installed!
Warning: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!

I expect the emulator tool but I see no emulator tool below :

$ brew info android-commandlinetools | grep bin/
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/avdmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/lint (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/retrace (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/sdkmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/apkanalyzer (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/screenshot2 (Binary)
$ 

EDIT0 : Thanks to @gtxtreme, I finally managed to install the Android emulator tool with these commands :

$ sdkmanager --list | grep emulator
  emulator | 34.2.16 | Android Emulator | emulator
  emulator                                                                                 | 34.2.16           | Android Emulator
$ yes | sdkmanager --licenses > /dev/null
$ sdkmanager --install emulator
[=======================================] 100% Unzipping... emulator/._NOTICE.tx

$ which emulator
$ export ANDROID_SDK_ROOT=/usr/local/share/android-commandlinetools
$ PATH="$ANDROID_SDK_ROOT/emulator:$PATH"
$ which emulator
/usr/local/share/android-commandlinetools/emulator/emulator
$ 

Solution

  • You can install an emulator using the sdkmanager command which you already have

    1. For generic skin emulator with default apis (without google apis) for use with Intel Macbook on CI (Can use google_atd too):

    2. List All System Images Available for Download:

    sdkmanager --list | grep system-images

    Download Image: sdkmanager --install "system-images;android-30;aosp_atd;x86"

    Create Emulator:

    echo "no" | avdmanager --verbose create avd --force --name "generic_api30_aosp_atd_emulator" --package "system-images;android-30;aosp_atd;x86" --tag "aosp_atd" --abi "x86"

    You can then launch Emulator using CLI documentation, which can be found here

    You can take a look at the commands to install a new emulator here. The above commands have been taken from this gist