3. Connect Something that Runs Your App

You have three options to run apps from within Android Studio on a x86 based Windows machine:

Use a physical device – faster execution time but less devices to test on

Use the x86 based emulator – requires Intel VT-x and Intel HAXM

Use the ARM based emulator – no further requirements but slower than the other options

3.1 Use a Physical Device

While you can try the app on the emulators that come with Android Studio only running it on the physical target device tells you if everything works. It will also be faster than an emulator.

But Android devices are configured to only install apps from the Play Store. To change that and enable sideloading apps you have to enable the phone’s developer options first:

Go to Settings | About Phone

Scroll down to the end

Tap the build number 7 times

You’ll get a confirmation that you are a developer now.

The previous steps created a new settings item – Developer Options. Open these options, check “Enable USB debugging” and confirm the change.

Now connnect your phone to the PC using an USB cable. From now on this will result not only in a notification that your phone is connected for charging but also an additional one that USB debugging is active.

You’ll also get asked whether to allow USB debugging once or from this computer in general. Make shure to accept or the phone will not show up in Android Studio.

When you now start your app from Android Studio the “Select Deployment Target” window should show your phone as a running device. What if it doesn’t?

There can be various reasons for the phone missing from the list. In my case (Moto G 2nd generation) checking Windows Device Manager showed that the Motorola ADB interface was missing (file transfer was working fine). To fix this first install Google USB driver:

Window content changes again. Click the “Have disk” button and select the path to your Android SDK – which defaults to “C:\Users\\AppData\Local\Android\sdk” – followed by “\extras\google\usb_driver”

Select android_winusb.inf and click Open. Then click OK

Window shows a list of drivers. Select “Android ADB Interface” and click Next

Accept the warning message and finally you’ll get a window saying that Windows has successfully updated the driver software for the device

Now the device should show up in the “Select Deployment Target” window’s list – click OK to start debugging.

On the phone accept the USB debugging request. You’ll also see an option to always accept debugging from this computer which will save some taps. After accepting the debug request your app will show in the app drawer. Start it to see all the ready-made glory.

The only thing that may stop you now is a really old phone. The app’s minimum supported API level is 15 which corresponds to Android version 4.03 or 4.04 named Ice Cream Sandwich. If your phone has an Android version prior to that it will be listed as incompatible. Lowering the API level by lowering minSdkVersion in the app’s gradle script should get the app running.

3.2 Use the x86 Based Emulator

On x86 based machines the x86 based emulator can directly access the hardware and will yield better performance than the ARM based emulator. This is accomplished by using Intel’s Hardware Accelerated eXecution Manager for Android emulators (HAXM) which in turn requires machines to support Intel’s Virtualization Technology (VT-X). You may have to enable VT-X in BIOS.

Virtualization solutions like Windows’ Hyper-V or VirtualBox and even anti-virus software like Avast use VT-X, too. But only one at a time can use VT-X. If you want to keep those you can use Visual Studio Emulator for Android which is compatible with Hyper-V or create a dual-boot setup to switch. This section will focus on Google’s emulator.

To check if your computer supports VT-X and other virtualization solutions are switched off you can use CoreInfo.exe from Microsoft’s SysInternals tools:

Download the zip file and unzip it into a directory of your choice

Open a command window

Drag CoreInfo.exe out of Explorer into the commmand window and hit Enter

In the output check the lines starting with “HYPERVISOR” and “VMX”:HYPERVISOR - Hypervisor is present
VMX - Supports Intel hardware-assisted virtualization
-> VT-X is not supported (nor is the hypervisor) – no Intel HAXM for you

HYPERVISOR * Hypervisor is present
VMX - Supports Intel hardware-assisted virtualization
-> VT-X is supported but Intel HAXM cannot be used because the hypervisor is enabled

Go to the Android SDK directory which is “C:\Users\\AppData\Local\Android\sdk” for a default installation

From there go to “\extras\intel\Hardware_Accelerated_Execution_Manager” and run intelhaxm-android.exe

The x86 based emulator was already installed with Android Studio so you should now be able to run your app in it. As I use Hyper-V that’s all I can say about the x86 based emulator. The next section also has some general info about how to use an emulator.

3.3 Use the ARM Based Emulator

The ARM based emulator works exactly like an x86 based emulator. The only drawback is that it cannot use hardware acceleration on an x86 based PC and is way slower as a result.

To use the ARM based emulator you need to download a new system image and create a virtual device from it in Android Studio. The download will be about 226 MB for API level 23 and take about 2 GB disk space when installed.

The following steps will create a device similar to the x86 based default device, currently emulating a LG Nexus 5 with API level 23:

The “Android Virtual Device Manager” window now shows your new image and you can close it

Now run your app on the new ARM based emulator:

In the “Select Deployment Target” window select the new ARM device from the “Available Emulators” list

Optionally check “Use same selection for future launches”

Click OK

App in Emulator

After a few seconds the emulator shows up and boots Android which will take a few minutes (8 for me). Once that is done:

Click on the device and press the left mouse button while moving the mouse to unlock the screen

Click on the Apps icon (round icon in the middle with spots on it)

In the App drawer find “My Application” and click it

Your app starts and greets the world

Next to the emulator is a toolbox with buttons simulating hardware actions like rotating the device. The ellipsis at the bottom let’s you access the extended controls window where you can for example send an SMS to the device. You close the emulator by clicking the respective button at the top of the toolbox.

4. Clean up

While Android Studio automatically installs the app on the target device when you run it you have to uninstall it manually.

You can also delete the project from the previous part if you don’t want to test Git with it in the next part. Its default location is in “C:\Users\<AccountName>\AndroidStudioProjects”.

If you don’t use the x86 based emulator you might want to delete it as it fills about 1.8 GB. Emulators are located in “C:\Users\<AccountName>\AppData\Local\Android\sdk\system-images\”.