Android Studio 2.0 comes with major improvements to the Android Emulator, now known as Emulator 2.0. When you install Studio, you can create your first virtual device at the same time. The default device is based on the Nexus 5, and it uses the most recent version of Android, API level 23, representing Android 6.0, Marshmallow. To see all of the settings for this device, pull down the menu, and choose View Details. You'll be able to see here where the device definition is stored, and lots of other settings.
- [Voiceover] Once you've installed the Intel HAXM software, you're ready to create and use virtual devices. To see your virtual devices and to create new ones, go to the menu and choose Tools, Android, AVD Manager. When you first install Android Studio, you have the option of creating a default virtual device, but you might have to do some configuration on it before you use it. If you see a virtual device there and you want to make sure it's starting from scratch, pull down the menu on the right by clicking the down arrow, and choose Wipe Data.
Then click Yes to confirm, and that will ensure that you're starting with a brand new device. Then, click on the pencil icon to look at the current settings. My default device has a name of Nexus 5 API 23. It's screen size and pixel density are set up to emulate the Nexus 5 cellphone. If I want to emulate a more recent phone, I can click Change, and I can change the profile to say the Nexus 6P, or the Nexus 5X, or I could even change to a tablet form such as the Nexus 9.
I'm going to stick with the Nexus 5, so I'll just click Cancel. I can also change which API level I'm supporting, by clicking Change and then downloading API levels that I want. If you don't see an API level you're interested in here, cancel out of the AVD Manager completely, then go back to the SDK Manager, and download the API level that you want to emulate. For example, if I wanted to create a virtual device to emulate Ice Cream Sandwich, Android 4.0.3, I should first download and install that API level into my Android Studio installation.
I'll go back to the AVD Manager, and once again I'll edit this AVD. One more thing about the API level. Notice that I'm using Android 6.0 with Google APIs. You can also create virtual devices that emulate the open source version of Android, from the AOSP or the Android Open Source Project. Which you choose depends on whether you want to use Google APIs. In the next section, you can set the startup size, and the orientation.
The scale is set by default to auto, and that means as you open the virtual device it will size itself depending on the size of your screen, but you can control the size of the virtual device by choosing one of these options. I'll accept the default of Auto. The orientation will be set initially to either portrait or landscape, but as you'll see in the new version of the emulator, it's quite easy to change the orientation at runtime. There are also some options for how you emulate graphical performance, and whether you want to enable a device frame.
To get to more settings click the button labeled Show Advanced Settings, and scroll down. You can turn on camera emulation, control the network emulation, and you can control the amount of RAM that you allocate to memory, to the heap, to internal storage, and to an emulated SD card. Finally, way down at the bottom, make sure you have this option turned on. Enable keyboard input. That will allow you to type values into applications without having to use the virtual device's on-screen keyboard.
Now, I'm leaving my RAM set to the default of 1536 megabytes. If you want to change to a larger amount, you could for instance switch to gigabytes, and then change the value to 2, but that would take up all the RAM that I allocated to the Intel HAXM software. That's fine, you just need to know you're doing it. Now I'm going to accept all of the default settings, so I'm just going to click Cancel, and then I'll start up the virtual device by selecting it in the list, and then clicking the Launch button.
Then I'll close the AVD Manager, and run. It says HAX is enabled, and HAX is working and emulator runs in fast virtual mode. This is telling me that the Intel HAXM software is working as expected. If you see this message, ADB server notified, that just means that the ADB server isn't fired up yet. I'm going to start it up in just a moment, once the emulator has started up successfully. Once the emulator starts up, it'll look like this, and you'll see the Android operating system's initial screen.
If you see the welcome message, you can click Got It, and if you want to get rid of these initial notifications, you can drag down from the top, and then swipe to the right to get rid of them. I'll talk in more detail about how to use this new version of the emulator in another video, but to wrap up this demo, I'll start up the application. I'll click the Android monitor tab at the bottom, and I see the message that the ADB server is starting up, and then in the list of available devices, I see my emulator.
Then I'll click my Run button up at the top, and immediately I see the select deployment target dialog. This appears a lot faster than it did in previous versions of Android Studio. In the past, the application would be built for deployment, and then you would see this dialog. Now, the dialog appears right away, and once you click OK, then the application will be packaged. I'll click OK, I'll go back to the run window to see how things are going, and I'll wait for a message indicating that the application has been packaged and is being deployed to my device.
I see launching app, and then I'm switched to the logcat window. I'll go back to the device, and I see my app is being displayed, so if all that's working for you, you've successfully launched your first app on your first virtual device in the new version of the Android emulator.
- Installing Android Studio on Mac and Windows
- Creating Android Studio projects
- Setting up the development environment, including HAXM and the new Android emulator
- Importing existing code into Android Studio projects
- Exploring the interface, including the editor and project windows
- Managing project builds and dependencies
- Creating new Java classes
- Refactoring code
- Using templates
- Using breakpoints and watch expressions
- Updating apps with Instant Run
- Using Git for version control
Skill Level Beginner
Q: This course was updated on 04/27/2017. What changed?
A: New videos were added that highlight the new features introduced in Android Studio 2.3. In addition, the following topic was updated: update apps with Instant Run.