Running One or More Emulators through CLI using Android Studio

(Using Windows 10)

Subscribe to our newsletter and never miss any upcoming articles

Listen to this article

Android Studio as an IDE is great to an extent, however, when utilizing its Android Virtual Device (AVD) Manager, it can become frustrating, especially if you wish to run more than one emulator at a time to test features on a project, for example; chatting, file streaming, etc. Fortunately, the Windows command prompt is capable of launching any number of emulators (or as many as your processor can handle!). This will be a step-by-step guide on how to create these emulators and get them up and running.

Creating an AVD in Android Studio:

To create an AVD, you must first have Android Studio running and open. Once open, you will need to navigate the top section of the IDE where you will see the following icons: image_2021-03-09_115651.png

To open the AVD Manager, select the circled icon in the above image. This should open a window that looks like this: image_2021-03-09_115923.png

From here, select "Create Virtual Device", and you will be taken to a window that lists a great number of virtual devices. Personally, I recommend the "Pixel XL" and/or the "Pixel 3a XL", but it is completely your choice. After selecting one, and clicking "Next", you will need to select a system image for the device. I use "R" as it is the most up-to-date image. You will have to download the image before moving on to the next step.

After successfully installing a system image and clicking "Next", you will be taken to the Verify Configuration window and from here, you can rename your emulator (I'd recommend a short name or the automatically generated one as this will be useful later). One other thing to note on this step is the "Emulated Performance" option. If your machine has a decent graphics card, than I would suggest selecting the "Hardware" choice. If you know your machine isn't capable of handling a great deal of graphical content and has low processing capabilities, select the "Software" choice. If you are unsure how good your graphics card is, keep the "Automatic" option selected. In addition to these choices, if you select the "Show Advanced Settings" and scroll back down to "Emulated Performance", you will see the option for how the device will boot. For faster boot up times (let's say to quickly test code), you can have the "Quick Boot" option selected, however, I find that the emulator and the projects you install onto the device will work best if you have it Cold Boot upon start-up. This, of course, will take longer (maybe about a minute or so) but in the end is worth it. From here, you can select "Finish" and you will now see your emulator listed in the AVD Manager.

Locating and Running your Emulator in CLI

1) To open your CLI, you can click the Windows key + R. This will open the "Run" box. Type cmd into the textbox and click Enter or OK. Once your CLI is open, navigate to the directory where your Android SDK exists and open the "emulator" folder. For example, mine is located in my D drive in a folder called "AndroidSDK_dec10_2020" so I use the commands:

D:
cd AndroidSDK_dec10_2020/emulator

2 (optional)) From here, in order to list the emulators that exist on your machine, you can use the command:

emulator -list-avds

3) I typically copy the name of an emulator I wish to use from the list and then use the command:

emulator -avd emulator_name

3.a) If you chose to have the emulator "Quick Boot" on startup and wish to cold boot the device you can use:

emulator -avd emulator_name -no-snapshot-load

This will boot your chosen emulator.

To now boot a second emulator, just go through the above steps again in a new, separate CLI window.

Locating and Running your Dart Project with the Emulators

Open a new, separate CLI (If you are running an emulator, there will be two CLI windows; one for your emulator, and one for your project). Navigate to the folder where your project exists (specifically wherever the pubspec.yaml file and use the command:

flutter run

If you have two emulators running, your CLI will prompt you like this: image_2021-03-09_125427.png

Keep in mind that whatever order your emulators were booted in, will be the same order that they are presented as. So using my picture above, you can see that [1]: sdk gphone x86 arm (emulator-5554) would be the first emulator I had booted on my machine. Do be careful while running numerous emulators on your machine as this can be a stressful activity for your processor!

Happy coding!

No Comments Yet