In this post, we will see step by step guide to create and setup Android Virtual Device, an Android emulator
What is an emulator
Emulator is something which closely resembles real device like mobile or tablet, where we can set the configuration such as RAM, OS version, processor, sd memory space, camera etc.
Android SDK gives an option to create emulator based on required specifications. so Android Virtual Device (AVD) comes with Android SDK.
Download
- Navigate to android.com/studio and click on “DOWNLOAD ANDROID STUDIO” specific to your OS.
- Open the Android studio > SDK Manager
- You will see 3 tabs “SDK Platforms”, “SDK Tools”, “SDK Update Sites”
Select the following checkboxes from each tab as mentioned below and click OK to download the Android OS and other necessary components.
Under the SDK Platforms tab –
- Respective Android API level (i.e which version of android OS running on your mobile)
[e.g – Android 12.0 (API 31)]
Select the checkboxes as mentioned above image.
Note – when a new version of android appears, you can check the latest version and download, which we will use to install as OS in android emulator.
Under the SDK Tools tab –
Check options such as
- Android SDK Build-Tools
- Android Emulator
- Android SDK platform-tools
- Android SDK tools
- Google Play services
- Intel x86 Emulator Accelerator (HAXM)
Under SDK Update Sites tab –
Check all options
and click on Apply to download and Finish so all required components will be downloaded.
Android studio command line option –
If you don’t want the complete android studio to install, you can download the CLI version from below link –
https://developer.android.com/studio#downloads
Navigate to the Command line tools only section and download the zip files based on the OS.
You will have to do use sdkmanager
command to download and install all the components we have seen above, need some experience into understand each command.
To find all the commands to download and install, you can refer sdkmanager
Set environmental variable:
[How to : set Env variable]
Add environmental variable
variable name : ANDROID_HOME
value: /Users/MyUser/Library/Android/SDK
Edit environmental variable
variable name: path
value: ;/Users/MyUser/Library/Android/SDK/tools;
/Users/MyUser/Library/Android/SDK/platform-tools;
Enable Developer options
On Android mobiles or tablets
- navigate to Settings > About / About phone
- Scroll down and tap around 7 times on Build number
- Confirmation popup comes with text “Developer mode has been enabled” or “you are now a developer”
- Now come back to Settings, and you can see Developer options, turn ON this option.
- Now connect mobile / tablet to the computer, you will see device shows “USB debugging connected”
ADB commands for android
Get android device information by ADB commands
[Device can be mobile, tablet or emulators]
Connect device to computer in debug mode or open android simulator,
then, open command prompt and type
adb devices
: lists devices connected to computer
List of devices attached emulator-5554 device
If in case, adb devices shows no result, better to use below troubleshooting steps:
type: adb kill-server and key press enter
then, adb start-server and key press enter
then try, adb devices [you should be able to see the device details now]
Note: From the above screenshot, adb devices have any one of the states
[Serial number] [state]
if device is connected, then state shows “device”,
if device is not connected properlly or not responding, then state shows “offline”
If no device connected, then result will be blank
Solution if adb command doesn’t work directly from start –> Run
Navigate to the platform-tools folder under AndroidSDKInstall folder, key press SHIFT and right click then select “Open command prompt here”, now adb command should work.
reference https://developer.android.com/studio/command-line/adb.html
Android Emulator
- Open Android Studio, More Actions > AVD Manager
- On the manager dialog, click on “Create Virtual Device…” to create a new emulator
- Select category as “Phone” and choose a device model from the available list and click Next
- Select appropriate android API level [version] from the list displayed and click Next
- Change or leave as it is the name of the AVD and click Finish
Now the above steps will launch a new android emulator to install and test mobile applications
Every time you want to launch the emulator,
- Open the android studio
- Tools > AVD Manager
- Click on the play icon from the available emulators to launch
There are other ways also to launch the emulator with out android studio, refer here
This site definitely has all off the info I needed concerning this subject and didn’t know who to ask.