Xamarin Android Emulators – Best Practices
Android emulators are designed to run in many different configurations to simulate the Android OS on various devices. Each configuration is known as a virtual device. Deploying and testing an app on an emulator requires selection of a pre-configured virtual device that simulates a physical android device.
Learn how to create and accelerate the Xamarin Android emulator for maximum performance, as well as how to use the Android Device Manager to create and customize virtual devices. Not only this, but also how to customize the profile properties of a virtual device.
Creating the Android Emulator
First, go to the Android Virtual Device (AVD) Manager and click on Create button. A pop up window like the one below appears: “Create New Android Virtual Device.”
Note: the steps below are indicated by the numbers marked in the picture. (For example Step 1 indicates point 1 in the picture)
Create a name for the AVD. Ensure the name is unique.
Select the Android version to be tested by the developer. The emulator will run that Android operation system based on this version selected.
Choose the CPU/API where the Android version will run. The third step is the very important because API consumes quite a lot of memory. The API you choose must therefore be efficient enough to run the Android emulator. Google API x86 is highly recommended as it’s usually more efficient.
Select the RAM/memory option: this step is also very important because the system will allocate RAM to the emulators. Each emulator should have a minimum of 1536 RAM, but it is recommended to choose 2GB RAM.VM, while Heap memory should be 64MB and above. Internal storage is also important and should be minimum 768MB. SD Card memory space should be 500MB at least.
For “Emulation option”, always select the Host GPU option. This would run XHAM resources internally. Un-check the “Snapshot” option, because that will create snapshots of your virtual device, taking even more system memory, which at times would not be cleared by the AVD manager.
Running the Android Emulator
Launch the Android Emulator from the AVD (Android Virtual Device) Manager. With this tool, the emulator can be launched either from the Start menu>>All Programs>>Android SDK Tools>>AVD Manager, or from Visual Studio 2017 and above (Run Visual Studio in administrator mode) Tools>>Android>>Android Emulator Manager. The screen shot below will help to understand better.
There will be another AVD manager popup window where all the created Android Emulators are listed. Simply select one of them and click Start button (See picture below)
Once the start button is clicked the “Launch Options” popup window appears as seen below. Select “Wipe user data” option. This will wipe all the user data in the emulator. Uncheck afterwards.
- DON’T close the emulator. Instead, stop the debugging option and run the code again.
- KEEP more space in the working drive like C Drive (Operating System located drive).
- REMOVE unnecessary Android images from the Android SDK Manager (run the Android SDK manager with administrator mode).
- DO NOT open too many emulators in run mode, because it will consume more system memory and slow down the computer.