Creating a Development Environment for Android Apps on Windows – Part 2: Connect a Device

First post in this series: Introduction to DbTradeAlert

Previous post: Install Android Studio

3. Connect Something that Runs Your App

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

  1. Use a physical device – faster execution time but less devices to test on
  2. Use the x86 based emulator – requires Intel VT-x and Intel HAXM
  3. 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:

  1. Go to Settings | About Phone
  2. Scroll down to the end
  3. 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:

  1. In Android Studio go to Tools | Android | SDK Manager
  2. In the Default Settings window switch to the SDK Tools tab
  3. Check “Google USB Driver”, click OK, and confirm the install

After the generic installation completed install the specific driver:

  1. Go to Windows Device Manager
  2. Find your phone – it will have a yellow error icon
  3. In its context menu select “Update Driver Software”
  4. In the “Update Driver Software” window select the “Browse my computer for driver software” option
  5. The “Update Driver Software” window shows new options. Select the “Let me pick from a list of device drivers on my computer” option
  6. Window content changes again. Select “Show all devices” and click Next
  7. 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”
  8. Select android_winusb.inf and click Open. Then click OK
  9. Window shows a list of drivers. Select “Android ADB Interface” and click Next
  10. 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:

  1. Download the zip file and unzip it into a directory of your choice
  2. Open a command window
  3. 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

HYPERVISOR - Hypervisor is present
VMX * Supports Intel hardware-assisted virtualization

-> VT-X is supported and the hypervisor is disabled – you can install Intel HAXM

If VT-X is supported and the hypervisor is disabled the next step is to install Intel HAXM. For that you first need to download the required module:

  1. In Android Studio go to Tools | Android | SDK Manager
  2. In the Default Settings window switch to the SDK Tools tab
  3. Check “Intel x86 Emulator Accelerator (HAXM Installer)”, click OK, and confirm the change

After the download finished install the new module:

  1. Switch to Explorer and make shure it shows hidden directories
  2. Go to the Android SDK directory which is “C:\Users\\AppData\Local\Android\sdk” for a default installation
  3. 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:

  1. In Android Studio click Tools | Android | AVD Manager
  2. In the “Android Virtual Device Manager” window click the “Create Virtual Device” button
  3. In the “Virtual Device Configuration” window, “Select Hardware” step, click the “Next” button
  4. In the “Virtual Device Configuration” window, “Select a system Image” step, switch to the “Other Images” tab and click the refresh button beneath
  5. Click Download on the topmost entry: Release Name = Marshmallow; API Level = 23; ABI = armeabi-v7a; Target = Android 6.0 (with Google APIs)
  6. In the “SDK Quickfix Installation” window, accept the license terms
  7. After the installation finished click “Next” to go back to the “Virtual Device Configuration” window
  8. Select the new image and click the “Next” button
  9. In the “Virtual Device Configuration” window, “Verify Configuration” step, append ” ARM” to the AVD name, and click the “Finish” button
  10. 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:

  1. In the “Select Deployment Target” window select the new ARM device from the “Available Emulators” list
  2. Optionally check “Use same selection for future launches”
  3. Click OK
DbTradeAlert - Setup - Android - TestApp in Emulator

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:

  1. Click on the device and press the left mouse button while moving the mouse to unlock the screen
  2. Click on the Apps icon (round icon in the middle with spots on it)
  3. In the App drawer find “My Application” and click it
  4. 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\”.

Next post: Install Git

Additional Ressources

Sysinternals Suite download:
Visual Studio Emulator for Android:
Switch easily between VirtualBox and Hyper-V with a BCDEdit boot Entry in Windows 8.1:

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s