AVD - Android Virtual Device
👉 Overview
👀 What ?
Android Virtual Device (AVD) is essentially an emulator system that represents a specific physical Android device. It is used to create virtual devices running the Android system, which can be used for testing and running Android applications in a simulated environment before deploying them on physical devices.
🧐 Why ?
AVDs are crucial components in Android application development. They allow developers to test their applications on a variety of devices and Android API levels, without needing to have each physical device. This ensures that the applications are compatible with a wide range of devices, screen sizes, resolutions, and Android versions. It also facilitates the debugging process by providing detailed logs and offering features like 'fake' GPS location and simulated incoming calls and messages.
⛏️ How ?
To create an AVD: 1. Open the Android SDK Manager. 2. Click on the 'Tools' menu and select 'Manage AVDs'. 3. Click 'New' to create a new AVD. 4. Fill in the details for the new AVD, including the name, device, target Android version, and other hardware options. 5. Click 'OK' to create the AVD. To run an AVD: 1. From the Android SDK Manager, click on 'Tools' > 'Manage AVDs'. 2. Select the AVD you want to run, then click 'Start'. 3. Click 'Launch' in the dialog that appears. The emulator will start and you'll see a new window representing your virtual device.
⏳ When ?
AVD was introduced in 2009 with the release of Android 1.5 (Cupcake). It has been a vital tool in Android development since then, with regular updates to support new Android versions and devices.
⚙️ Technical Explanations
Under the hood, AVD uses the QEMU (Quick Emulator) open-source software to emulate the ARM or x86 architecture of physical Android devices. It simulates the entire software stack, including the kernel, system libraries, and user applications. The Android system running on the AVD is a full Android stack, not a simulated or cut-down version. This allows it to behave almost exactly like a real Android device. However, because it's running on an emulated CPU, it may run slower than a real device. The AVD also provides a set of hardware controls (buttons, touchscreen, etc.) and sensor inputs (GPS, accelerometer, etc.) that can be manipulated by the user or programmatically by the application running on it.
For example, let's say you're developing an Android app and you want to test it on a Google Pixel 4 running Android 11, but you don't have the physical device. You can use AVD to create a virtual Pixel 4 running Android 11. Here's how:
- Open the Android SDK Manager: This is where you can manage your AVDs. You can find it in your Android Studio installation.
- Create a new AVD: Click on the 'Tools' menu and select 'AVD Manager'. Click 'Create Virtual Device' at the bottom-left of the window that pops up.
- Choose a device: Select 'Pixel 4' from the list of devices and click 'Next'.
- Choose a system image: Choose the system image for Android 11. If it's not available, you might need to download it first. Click 'Next' when you're done.
- Configure the AVD: Give your AVD a name (e.g., 'Pixel 4 Android 11'). You can also adjust other settings if needed, but the defaults should be fine for most cases. Click 'Finish' to create the AVD.
Name: Pixel 4 Android 11
Device: Pixel 4
Target: Android 11.0 (Google APIs)
CPU/ABI: Google APIs Intel Atom (x86)
Skin: Pixel 4
- Run the AVD: Go back to the 'AVD Manager', select your newly created AVD, and click 'Start' > 'Launch'. A new window will open representing your virtual Pixel 4.
- Install and run your app: You can now install your app on the virtual device and run it just as you would on a real device. For example, from the command line, you could use the
adb install
command:
adb install path/to/your/app.apk
In this example, the AVD allows you to test your app on a Pixel 4 running Android 11, even if you don't have the physical device.