Home

Android Emulator - How to Setup and Use it for App Testing

I’ve seen many people test app by building APK manually, sending it to phone, installing it, running it. It is easy if you are building a simple app and youhave the complete error free code. But this is not the case when it comes to building a complex app. You may need to do these steps a thousand times for testing each and every change in the project. So to improve productivity we need something better. Luckily Android Studio has a solution built in - The Android Emulator. It is a small software (Its name is QEMU) that will run an instance of Android OS to test the app easily. In this article I will explain how to setup android emulator for testing. In addition to that I will also show you how to directly use smartphone instead of android emulator.

Setup Android Emulator

First open your android studio. Goto Tools ยป Android ยป AVD Manager. android-avd-manager-menu.png

This will show a setup screen like below. Click on Create Virtual Device android-virtual-device-wizard.png

Here you can select a predefined hardware. You can either create one that matches your phone by clicking **New Hardware Profile **or you can select a predefined one. In order to keep things simple I choose Nexus 5. After that click Next.

Android-Virtual-Device-Hardware-Profile.png Now it will ask for which version of android should be installed on the emulator. You can choose any version. But you should have the ROM image. When you download Android studio it will have one image built in. In my case it is Marshmallow x86_64 (64bit) version. Bold text for Marshmallow is due to this. If you want another version, say Nougat, you can click on that Download link. It will be around 300-500 MB in size and will require internet. Here I’m choosing Marshmallow because I already have it. After that click next.

![Android-Virtual-Device-System-Image.png”imageanchor=“1”>(Android-Virtual-Device-System-Image.png) Here you can choose some advanced settings like graphics driver, RAM etc. I would suggest to keep them as default. But if you are having a 64bit operating system (Check My Computer properties to check this) and you have selected HAXM when you installed Android Studio then you can choose the Graphics as Hardware GLES 2.0. This will improve the speed of android emulator dramatically. After that click Finish.

Android-Virtual-Device-Configuration.png It may take some time to close the window automatically. Wait for it. After that you will get a window like this:

Android-Virtual-Devices-List-in-AVD-Manager.png Now close it and click the Run button in the toolbar.

Android-Project-Run.png Now it will ask where you want to run it. There will be our android emulator listed in the second section. Select it and click OK. You may also check the option that says Use same selection for future launches. So Studio will not show this window next time.

![Android-Project-Run-Target-Emulator.png”imageanchor=“1”>(Android-Project-Run-Target-Emulator.png) Now the Android OS will boot inside the Emulator. If you have enabled Hardware Graphics then it will complete quickly. But if the booting didn’t complete in15 minutes then close it and create new/modify emulator and change graphics to software. In Software mode it will take a little more time to finish. Anyway wait for some time, may be 15 minutes. It will be less next time you open android emulator.

Android-Booting-in-Emulator.png Meanwhile you can see the log of booting inside Android studio like this:

Android-Emulator-Run-Log.png After booting it will automatically install the APK of the project and launch it for you. Here is the Calculator app I designed using WebView running insideandroid emulator.

Android-WebView-Calculator-App.png

Keep the emulator minimized whenever you don’t need it. After making modifications in the project click on the Run button again. Studio will do the rest.

Setup Smartphone

Android emulator is just a mocked version of Android. It is useful for quickly testing apps. But after the development of app it should be tested in a real device, a smartphone. Some developers, won’t use android emulator in the entire development process. I don’t like emulator much. I always use my phone for testing. So if want to do the same then here are the steps.

Enable USB Debugging

First of all you need to enable USB debugging in your smartphone. For that goto your settings and open Developer options.

Android-Developer-Options-Menu.png If there is no developer options then goto About phone then click on Build number for 5-7 times continuously. This will enable developer options.

Android-Build-Number-Menu.png

Now open developer options and enable this setting. After that connect your phone to computer using USB cable. You may see an alert showing some kind of signature of the computer. This is because of the encryption used by ADB. So allow it. But if nothing happened after plugging phone then you probably don’t havethe drivers for your phone. In that case follow next steps to install drivers.

Android-USB-Debugging-Switch.png

Install Drivers

For this first of all download the Universal ADB Driver from this link. Install it. After that search in start menu for Device Manger and open it. Inside device manager you will be able to find a device with ADB or Android in its name. Here is my phone listed:

Android-Device-ADB-in-Windows-Device-Manager.png

This may be different in name for different smartphones. But if you could find a similar one then you are good to go.

Run App

Come back to android studio and click on Run button. Now it should show two devices. One is our android emulator and other is the phone. This time select the phone and click OK.

Android-Project-Run-Target-Real-Device.png Wait for a moment. Meanwhile Studio will build the APK and install it in your phone. After that it will automatically launch the app. Here we are testing the app in a real device, therefore we will get more insights about the performance of the app. Finally, here is a simple WebView Calculator app running in my Moto G Turbo Edition.

Android-WebView-Calculator-App-Running-in-Real-Device.png

Did it work? Let me know in your comments below. I will be happy to assist you.

To be continued..