In this short tutorial, we are going to cover two useful tools for keeping your development packages up to date and for emulating the testing devices. The former is called SDK Manager, which integrates easy updates for the Software Development Kit (SDK), including tools, platforms, and other components into packages. The latter is AVD Manager, which allows you to create and manage Android Virtual Devices (AVDs). AVDs are basically device emulators.
Both tools are accessible through the graphical interface of Google's own Android development environment, Android Studio, as shown in Figure 1 or through the command line. If you are not familiar with it, you can check out the reference section at the end of this article or our previous tutorial, "Using Android Studio". The goal of this tutorial is to at least point out the most common usage popular among developers and explain some different options.
Figure 1: Tools on Android Studio
Managing Packages from the SDK Manager
You can start SDK Manager from Android Studio's menu by choosing "Tools -> Android -> SDK Manager" or by clicking the toolbar icon. You should see the main dialog, as shown in Figure 2. The first thing you can verify is whether the SDK location is indeed correct. In my case, it is under "C:\android-root\sdk\" as shown. There are three tabs below that allow you to choose your installation options from Platforms, Tools, or Update Sites. Furthermore, there is a checkbox for "Show Package Details" on the lower right corner; I strongly recommend that you enable it as well. That way, you clearly can see what packages are actually installed on the machine.
Some of the system images take up several gigabytes of your storage space, but you probably will never have a need to use some of them. For example, you perhaps will not do apps for TV or smart watches, so you can feel free to uncheck those system images. And, if you are specific about apps targeting at specific CPU types—for example ARM—you can remove those Intel 32-bit or 64-bit system images. If you plan to work only on apps for the most recent devices with newer API levels, say Android 7.0 Nougat or later, any APIs before that version can be unchecked. Checkboxes on the items can be used to install, uninstall, or update. Once you confirm your selections and click the "Apply" button, the component installer will start as in Figure 3, responding to your request.
Figure 2: SDK Manager
Figure 3: SDK Component Installer
Using SDK Manager from the Command Line
Although it is convenient and simple enough to interact with the SDK Manager through a graphical interface, we still sometimes need to accomplish similar goals in a programmatic mode; for example, keeping a target platform up to date for a specific device in a fully-automated setup. To locate the executable, we first go to the Android SDK installed root folder. In my case, it is at "c:\android-root\sdk\". From there, continue to look under the subfolder "tools\bin\". We can test the command "sdkmanager --list" to take an inventory of what packages are currently installed on the machine and what are available from the remote server, as in Figure 4. To install available packages, you specify the quoted names separated by spaces and provide each of their folder names separated by semicolons, as in the following code example. It tries to install the platforms for both API levels 21 and 24. Similarly, the "--uninstall" and "--update" options follow the same rules.
sdkmanager "platforms;android-21" "platforms;android-24"
Figure 4: SDK Manager Command Mode
Managing Android Virtual Devices (AVDs) from the AVD Manager
You can start AVD Manager from Android Studio's menu by choosing "Tools -> Android -> AVD Manager" or by clicking the toolbar icon. Figure 5 shows the main dialog with the list of currently available AVDs. If you have not created any, the list will be empty. The AVDs are the configurations that model the characteristics of the target Android hardware devices. AVD Manager is a handy interface that allows you to create and manage AVDs. Click the "Create Virtual Device..." button to begin configuring a new AVD. You will be taken to the "Select Hardware" dialog. For example, I am trying to emulate a Nexus 6P phone device, so I will select the "Phone" category and the "Nexus 6P" profile. If your hardware profile is not in the predefined list, you can always customize one. Then, you will select a system image on the next dialog. It is highly recommended you look under the "Recommended" tab and click "Download" when suggested. On the next "Verify Configuration" dialog, you can click the "Show Advanced Settings" to adjust memory and storage, network, camera, and so forth. After a few minutes, a new AVD is created; it will appear in AVD Manager. You can start the emulator for your AVD by clicking the green triangle. Note that it may take a few minutes to initiate your emulator, so please be patient.
Figure 5: AVD Manager
Figure 6: AVD
Using AVD Manager from the Command Line
As in the command mode for SDK Manager, we also can find the executable in the same file folder for the AVD Manager version. In Figure 7, we test the basic functionality by listing all the available AVDs by issuing the "avdmanager list avd" command. To create an AVD, you start by naming it with the "-n" option and specifying the quoted SDK info with the "-k" option and detailed configurations separated by semicolons. The following example creates an AVD named "avd_test_1" using the ARM system image for API level 24. After that, you can re-list the AVDs and you should be able to find your newly created virtual device towards the end of the list.
avdmanager create avd -n avd_test_1 -k "system-images;android-24; google_apis;armeabi-v7a" Name: avd_test_1 Path: C:\Users\Chunyen\.android\avd\avd_test_1.avd Target: Google APIs Based on: Android 7.0 (Nougat) Tag/ABI: google_apis/armeabi-v7a
Figure 7: AVD Manager Command Mode
Once you have created those AVDs, you can use the Android emulator to develop and test apps without physical devices. From the AVD Manager, you simply can double-click to start up the emulator or do it through the command line, as introduced in this section. If you connect any physical Android devices—such as phones, tablets, watches, and the like‐you will see them in the chooser dialog before you run your apps on them. An emulator usually will resemble a physical device model for your apps that are designed to run and test on. In addition to those features already configured in the AVD, various hardware characteristics, personal storage, and form factors also need to be taken into account. Now, we can start the emulator with the available AVDs by the following and choose the one, "avd_test_1", that was created before. Figures 8 and 9 illustrate some emulators provided by Android development tools. Once the emulator is up and running, you can interact with it through its named ID just like physical devices, such as by installing or uninstalling apps through the ADB debugging bridge, easily.
emulator -list-avds avd_test_1 emulator -avd avd_test_1
Figure 8: Mobile Emulator
Figure 9: Wear Emulator
Before your apps are ready for their official release to the public, they should be thoroughly tested and verified in as many devices and software configurations as possible. With the gigantic number of Android devices available out there, this requirement for hardware testing is almost unrealistic, especially for independent developers with limited financial resources. Therefore, using the SDK and AVD managers to create and emulate some of the most popular devices becomes one of the most affordable approaches. SDK Manager also will offer you the opportunity to preview the most recent features before they even exist on any physical devices. AVD Manager then allows you to configure virtual devices to resemble the software and hardware combinations for those devices already in the market. These tools covered in this tutorial are pretty critical pieces in the development process.
About the Author
Chunyen Liu has been a software veteran in Taiwan and the United States. He is a published author of 40+ articles and 100+ tiny apps, software patentee, technical reviewer, and programming contest winner by ACM/IBM/SUN. He holds advanced degrees in Computer Science with 20+ graduate-level classes. On the non-technical side, he is enthusiastic about the Olympic sport of table tennis, being a USA certified umpire, certified coach, certified referee, and categorized event winners at State Championships and the US Open.