Till now we were done with installation of Android studio and create First Android application. In the series of developing the android applications it is mandatory to run compile and run the applications on Emulator/Physical devices. Android has many OS levels. It's very hard to maintain all real devices for debugging. The behavior of each API level and the difference in screens depending on the model can be grasped to some extent with the emulator. To deploy the apps on real devices some times may not possible, so to test the apps we can use emulators.
In this chapter we are going to learn how to create AVD and deploy the application on emulator. To create an emulator we will use android Device Manager.
Device Manager is an android studio tool which will use to create and manage the emulators.
Launch Device Manager from Tools menu "Emulator" icon , we can also call it from "Tools" "Device Manager".
On Device Manager window we have one button called "Create device", click on it, will show the below Hardware Profile window.
This window will show the list of Hardware Profiles for Phones, Tablets, TV, WearOs and Automotives. Choose any Hardware Profile and click on Next button.
Now on System Image window choose an API which version of Emulator we want to create and click on Next button.
ABI: If it's Intel Core, select x86 or x86_64 and you're good to go. Here i have Mac M1 machine, so it will show arm64-v8a.
If your PC is 64-bit x86, x86_64 will work faster. Later, when using Google API, etc., it will not work unless the Emulator supports it. If you are using a third-party library, there is a cpu dependency, and depending on the library, it seems that emulation can only be done with armeabi-v7a.
On Verify configuration window we can also change some settings like Camera options, Storage settings etc.
Click Show Advanced Settings to enable advanced settings. In addition, this depends on the performance of the device to be emulated, so there are some that cannot be selected.
Now click on Finish button. It will create an AVD and will display under Device Manager devices list.
Now launch the AVD/Emulator by click on run icon of the selected emulator under Device Manager devices list.
Note that the created Virtual Device is about 500MB before it is started, but it expands to about 9GB after it is expanded, so if you create a lot, it will put pressure on the hard disk, so be careful, But from Android 10... This Virtual Device can be edited by clicking the pencil icon in Actions
When the emulator starts up, it used to be a single window, but now fits inside the IDE. However, this sometimes caused the emulator not to start or to be locked, so it was solved by making it independent like before (2021.1.1 patch 2)
If you want to display it in an independent window , uncheck "Launch in a tool window" in "Tools" "Emulator"
from Settings on Windows or Preferences on Mac .
There is a panel on the right. Also, if you click on the other "..." icon, an extended control will appear on the right side.
power supply |
Click to turn the screen on/off Press and hold to bring up a dialog to select Power off, Restart, Screenshot. |
volume up |
Click to reveal a slider control to increase the volume. Click again to increase the volume further, or adjust the volume with the slider control. |
volume down |
Click to reveal a slider control to decrease the volume. Click again to decrease the volume further, or adjust the volume with the slider control. |
left rotation |
Rotate your phone 90 degrees counterclockwise |
Right rotation |
Rotate your phone 90 degrees clockwise |
screenshot taking |
Click to take a screenshot of your device. The default save location is your computer desktop. To change the save location, select … > Settings . Screenshots from Android Studio's Logcat allow you to add skins and make detailed settings. |
Switch to zoom mode |
Click to change cursor to zoom icon
Click the zoom mode icon again to return to normal screen size. |
return |
Go back or close a dialog box, options menu, notification panel, or onscreen keyboard. |
home |
Return to the home screen. A long press shows items specific to the API level in use. |
recently
(Recently used apps)
|
Tap to display a list of thumbnail images of recently used apps. Tap the image to open the app. Swipe left or right to remove a thumbnail from the list. This button is not supported on Android Wear. |
menu | You can see this on the home screen. keyboard shortcuts "Ctrl+M" "⌘M"
can be used to simulate a menu button, enabling operations such as opening a menu and selecting an app. |
resize | You can scale the size using the shortcuts ⌘↑ and ⌘↓. |
others |
Click to access additional features and settings shown in the table below. |
Install APKs | After dragging the APK file onto the emulator screen, an APK installer dialog will appear. After the installation is complete, the added app will appear in the list of apps. If you get an "APK failed to install" dialog, the app is not installed. |
add file | Drag any file onto the emulator screen and the file will /sdcard/Download be placed in the directory. Navigate to the location of the file in a manner appropriate to your API level. For example for API 22 go to: Settings > Device :Storage & USB > Internal Storage > Explore (virtual SD card). |
Ref: Run your app on the Android Emulator
If you click the More "..." icon in the emulator panel, extended controls will appear on the right.
Location | You can test the GPS, Fusedlocation provider, and simulate the latitude and longitude to the emulator. You can also use geospatial data in GPS Data Exchange Format (GPX) and Keyhole Markup Language (KML) files. |
Cellular | You can simulate network conditions. |
Battery | You can set the battery level, status, etc. of the battery and test it. |
camera | You can set the Virtual Scene displayed by the camera. |
phone | You can simulate incoming calls and text messages. |
Directional pad | If your AVD has a d-pad enabled in the hardware profile, you can use the d-pad in the emulator |
microphone | You can emulate what it would be like if your headset had a microphone. |
fingerprint | It can simulate 10 different fingerprint scans. |
Virtual Sensors | It can emulate some sensors such as accelerometers. |
Bug reports | You can check the bug report data. |
Snapshots | You can take a still image of the emulator screen in .png. |
screen record | You can shoot a video of the emulator screen in .webm. |
Google Play | You can sign in to Google Play. |
Settings | Setting the storage location of Snapshots, etc. |
Help | You can find shortcuts for each function. |