How to: How to run emulator
* Check available emulator system images from remote SDK repository

  ```console
  sdkmanager --list --verbose
  ```

* Make sure that the required SDK packages are installed, you can find out by above command.  To install, use the command below.  Whenever you see error complains about `ANDROID_SDK_ROOT` (or `ANDROID_HOME`), such as `PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT` or `PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value`, it means that you need to install following packages.

  ```console
  sdkmanager "platform-tools" "platforms;android-
" "emulator"
  ```

* Download emulator system image(s) (on the host machine)

  ```bash
  sdkmanager "system_image_1" "system_image_2"
  # e.g.:
  # system-images;android-24;android-tv;x86
  # system-images;android-24;default;arm64-v8a
  # system-images;android-24;default;armeabi-v7a
  # system-images;android-24;default;x86
  # system-images;android-24;default;x86_64
  # system-images;android-24;google_apis;arm64-v8a
  # system-images;android-24;google_apis;armeabi-v7a
  # system-images;android-24;google_apis;x86
  # system-images;android-24;google_apis;x86_64
  # system-images;android-24;google_apis_playstore;x86
  ```

* Run Docker container in privileged mode (not necessary for ARM emulator)

  ```bash
  # required by KVM
  docker run -it --privileged -v $(pwd)/sdk:/opt/android-sdk:ro thyrlian/android-sdk /bin/bash
  ```

* Check acceleration ability (not necessary for ARM emulator)

  ```bash
  emulator -accel-check
  
  # when succeeds
  accel:
  0
  KVM (version 12) is installed and usable.
  accel
  
  # when fails (probably due to unprivileged mode)
  accel:
  8
  /dev/kvm is not found: VT disabled in BIOS or KVM kernel module not loaded
  accel
  ```

* Create a new Android Virtual Device

  ```bash
  echo "no" | avdmanager create avd -n
-k
# e.g.:
  echo "no" | avdmanager create avd -n test -k "system-images;android-24;default;armeabi-v7a"
  ```

* List existing Android Virtual Devices

  ```bash
  avdmanager list avd
  # ==================================================
  Available Android Virtual Devices:
      Name: test
      Path: /root/.android/avd/test.avd
    Target: Default Android System Image
            Based on: Android 7.0 (Nougat) Tag/ABI: default/armeabi-v7a
  # ==================================================
  
  # or
  
  emulator -list-avds
  # 32-bit Linux Android emulator binaries are DEPRECATED
  # ==================================================
  test
  # ==================================================
  ```

* Launch emulator in background

  ```bash
  emulator -avd
-no-audio -no-boot-anim -no-window -accel on -gpu off &
  
  # if the container is not running in privileged mode, you should see below errors:
  #=> emulator: ERROR: x86_64 emulation currently requires hardware acceleration!
  #=> Please ensure KVM is properly installed and usable.
  #=> CPU acceleration status: /dev/kvm is not found: VT disabled in BIOS or KVM kernel module not loaded
  # or it's running on top of a VM
  #=> CPU acceleration status: KVM requires a CPU that supports vmx or svm
  ```

* Check the virtual device status

  ```bash
  adb devices
  # ==================================================
  List of devices attached
  emulator-5554	offline
  # "offline" means it's still booting up
  # ==================================================
  
  # ==================================================
  List of devices attached
  emulator-5554	device
  # "device" means it's ready to be used
  # ==================================================
  ```

Now you can for instance run UI tests on the emulator (just remember, the performance is POOR):

  ```console
/gradlew connectedAndroidTest
  ```