Run Your Apache Cordova App on Android
In Visual Studio 2013, the Cordova tools are released as a preview (CTP) version. Cordova tools will be released as part of Visual Studio 2015 and we recommend that you now use Visual Studio 2015 RC to develop apps using Visual Studio Tools for Apache Cordova. You can download Visual Studio from the Microsoft Download Center.
There are many options for running your apps built using Visual Studio Tools for Apache Cordova on Android. From Visual Studio, you can run and debug Android apps on the following emulators and devices:
Apache Ripple emulator (discussed in a separate article)
Visual Studio Emulator for Android
Android emulator
Genymotion emulator
Android device
Visual Studio Emulator for Android (Hyper-V)
Follow these instructions to run your app on the Visual Studio Emulator for Android. The emulator has the same system requirements as the Windows Phone emulator. For system requirements, see Run Windows Phone apps in the emulator in the Windows Dev Center.
Important
The Visual Studio Emulator for Android is only available in Visual Studio 2015.
To run your app on the emulator
Make sure that Hyper-V is enabled on your PC. Your PC must support the same system requirements as the Windows Phone emulator.
Important
The emulator is not supported in a virtualized environment.
With your app open in Visual Studio, choose Android from the Solution Platforms list. If you don’t see this list, choose Solution Platforms from the Add/Remove Buttons list to display it.
Choose one of the emulators, such as VS Emulator Android Phone.
Press F5 to start the app.
Visual Studio starts the emulator and runs the app.
Configure a high-performance emulator (no Hyper-V)
If you have a PC with an Intel processor, you can improve the performance of the Android and Genymotion emulators. To configure a high-performance emulator:
Disable Hyper-V. You can do this from Control Panel or from a command line, as described in the following procedures.
Warning
Disabling Hyper-V will prevent you from using the Visual Studio Emulator for Android and the Windows Phone emulator. However, you can still deploy to a Windows Phone device while Hyper-V is disabled.
(Android emulator only) Install the high-performance Intel Hardware Accelerated Execution Manager (HAXM) driver, if it isn’t already installed. (More information about the HAXM driver)
Configure the Android emulator to use hardware acceleration.
To disable Hyper-V in Control Panel
In the Control Panel, choose Programs and Features, and then choose Turn Windows features on or off.
Clear the check box for Hyper-V.
Reboot your PC.
Now you can install the HAXM driver.
Alternatively, you can configure Windows to start with Hyper-V automatically enabled or disabled using the command line.
To disable Hyper-V using the command line
Open an elevated command prompt (with administrative credentials), and type:
bcdedit /set hypervisorlaunchtype off
Warning
The bcdedit commands can prevent your system from booting if not executed correctly; be careful when using these commands.
If you’re adding this command to a shell script, use the following instead:
bcdedit /set hypervisorlaunchtype off shutdown /r
Reboot your PC.
If you want to re-enable Hyper-V later, use the following command, and then reboot your PC:
bcdedit /set hypervisorlaunchtype auto
If you’re using the Genymotion emulator, you can skip this procedure. For more information, see Genymotion emulator.
To install the high-performance HAXM driver (Android emulator only)
After disabling Hyper-V and rebooting, open the Android SDK Manager. To do this from a command line, go to the location of the SDK and type android.
On Windows, the Android SDK Manager.exe is installed in the following location: C:\Program Files (x86)\Android\android-sdk.
In the Android SDK Manager, look under Extras for the Intel x86 Emulator Accelerator (HAXM Installer). If the status column shows that it isn’t installed, select its check box, and then choose Install Packages.
Install the driver by going to sdk-path\extras\intel\Hardware_Accelerated_Execution_Manager and running intelhaxm.exe.
Tip
If the "intel" portion of the path isn’t present, the driver was not installed.
Now you can configure an emulator to use the driver. When you create or edit an emulator, you must use an Intel CPU and select the Use Host GPU option. For more information, see the next section.
Android emulator
Before you run your app on the Android emulator in Visual Studio, use the Android Virtual Device (AVD) Manager to create an emulator configuration, and then start the emulator from the AVD Manager. The following steps show how to do this. For more information, see the AVD Manager documentation.
To create an instance of the emulator
Open the AVD Manager. To do this from a command line, go the location of the SDK and type android avd.
On Windows, the AVD Manager.exe is installed in the following location: C:\Program Files (x86)\Android\android-sdk.
In the AVD Manager, choose Create.
Configure the properties for the new emulator.
The required properties are AVD Name, Device, Target, CPU/ABI, and Skin. Target represents an installed version of the Android SDK version (API set). Set this property to API Level 19.
Tip
If you want to target API 21, you can install the images for API 21 using the Android SDK Manager.
If you installed the high-performance HAXM driver in the previous section and chose an Intel CPU, select the Use Host GPU check box in Emulation Options.
Important
To use the high-performance emulator, you must also choose an Intel processor in the CPU/ABI section of the AVD dialog box.
Choose OK to close the configuration dialog box, and then choose OK again in the dialog box that shows all the emulator settings.
In the AVD Manager, select the new emulator, and then choose Start.
To run the app on the emulator
With your app open in Visual Studio, choose Android from the Solution Platforms list. If you don’t see this option, choose Solution Platforms from the Add/Remove Buttons list.
In the device list, choose Android Emulator.
Press F5 to start the app, or Shift+F5 to start the app without debugging.
Android 4.4 is required to attach the debugger. Otherwise, the app will run without debugging.
Tip
-
If you get an error that indicates you need to install a new version of the Android SDK, use the Android SDK Manager to install it. On Windows, the SDK Manager.exe is installed in the C:\Program Files (x86)\Android\android-sdk.
-
Visual Studio deploys the app to the Android emulator that is currently running. If no emulator is running, Visual Studio starts the last emulator that was created using the AVD Manager, and then deploys the app.
-
If you want to debug your app against Android versions 4.1.2-4.3, see the information about the jsHybugger plugin in the article Debug Your App Built with Visual Studio Tools for Apache Cordova.
-
Genymotion emulator
The Genymotion emulator is a popular alternative to the Android emulator that is included with the Android SDK. Here are a few tips for getting started with the emulator:
If you have trouble starting the emulator from a remote connection, try starting it locally, and then reconnect remotely if needed. The emulator requires OpenGL for rendering, and this may result in a conflict when starting the emulator.
You need a video card and video card drivers that support OpenGL. You may receive messages that indicate this. (If you connect to your PC remotely, you may also see this message. Try again after connecting locally.)
You may receive a message to check your VirtualBox network configuration when you try to start the emulator. Follow the link and instructions to modify or remove the "Host-only Network Adapter" from VirtualBox. (VirtualBox is included with the installation of the emulator.)
For high-performance emulation using Genymotion, disable Hyper-V before starting the emulator, as described earlier in Configure a high-performance emulator.
Android developer tools see Genymotion as a physical device. When you use Visual Studio to run the app, you instruct Visual Studio to deploy to an Android device.
To run your app on the Genymotion emulator
Start the Genymotion emulator.
With your app open in Visual Studio, choose Android from the Solution Platforms list. If you don’t see this option, choose Solution Platforms from the Add/Remove Buttons list.
In the device list, choose Device.
Press F5 to start the app, or Shift+F5 to start the app without debugging.
Android devices
Before you can use Visual Studio to run your app on a connected Android device, you must install the required driver:
Google USB driver for Google Nexus devices
You must also make sure that your device is in developer mode. For instructions, see “Enabling On-device Developer Options” and “Setting up a Device for Development” in the Using Hardware Devices page on the Android website.
To deploy a Release or Distribution configuration of your app, you must sign your app first. For more information, see Package Your App Built with Visual Studio Tools for Apache Cordova.
To run your app on an Android device
Make sure that you have installed the required OEM or Google USB driver.
Make sure that your Android device is in developer mode (see Using Hardware Devices on the Android website).
With your app open in Visual Studio, choose Android from the Solution Platforms list. If you don’t see this option, choose Solution Platforms from the Add/Remove Buttons list.
In the device list, choose Device.
Press F5 to start the app, or Shift+F5 to start the app without debugging.
When prompted, choose Allow USB Debugging.
Get the Visual Studio Tools for Apache Cordova or learn more
See Also
Concepts
Install Visual Studio Tools for Apache Cordova
Debug Your App Built with Visual Studio Tools for Apache Cordova
Package Your App Built with Visual Studio Tools for Apache Cordova