Programster's Blog

Tutorials focusing on Linux, programming, and open source

Set Up Android Emulator

After having set up Nativescript, you probably want to set up an emulator for testing your apps.

Steps

You can run the command below to list your available android devices and emulators:

tns device android --available-devices

After a fresh installlation, you will probably have nothing, with the following output:


Available emulators ┌─────────────┬──────────┬─────────┬───────────────────┐ │ Device Name │ Platform │ Version │ Device Identifier │ └─────────────┴──────────┴─────────┴───────────────────┘ Connected devices & emulators Searching for devices... Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.

The steps below will get you set up with an android emulator for version 6.0. This will not work inside a Virtualbox machine, or whilst Virtualbox, docker, or other virtualization software is running. More info.

Steps

First we need to create a new Android virtual device (AVD). To do this, we need to download an image for it to use (you only have to do this once)

sdkmanager "system-images;android-23;google_apis;x86"

Now create as many virtual devices as you want:

avdmanager create avd --name $name --package "system-images;android-23;google_apis;x86"

For example:

avdmanager create avd --name test --package "system-images;android-23;google_apis;x86"

Now if you run avdmanager list avd you should see:

Available Android Virtual Devices:
    Name: test
    Path: /home/stuart/.android/avd/test.avd
  Target: Google APIs (Google Inc.)
          Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86

Now we can run our emulator to see it working:

cd $ANDROID_HOME/tools
emulator -avd test 

You should see your new emulator:

References