How to run an Android app on a device from a virtual machine

I have a virtual machine with Windows 8 and Android Studio where I am currently experimenting with Android mobile development. I tried Eclipse as well but eventually decided to use Android Studio for a number of reasons which I won’t get into now because it is not relevant for this post.

Anyhow my problem with Eclipse and Android Studio is the emulator. It needs a lot of time to start and it crashes often. So I tested this week to run my sample app directly on an Android phone and it makes a huge difference for a faster development and testing, the app is loaded on the phone in a very short time.

The tricky part was though that I am developing in a virtual machine environment and the phone that I would be testing the app on is connected via USB to the main machine. Getting this to run wasn’t as difficult as I expected.

Prerequisites:

1. Virtual machine with Windows 8 and Android Studio running in VMWare Player

Instructions:

  1. Enable debugging on the Android device:
    1. On your Android device, go to Settings -> Develop Option -> check USB Debugging
  2. Enable unknown sources on the Android device:
    1. On your Android device, go to Settings -> Security -> check Unknown sources
  3. Connect the Android device via USB to the main machine: Windows on the main machine should recognize the phone.
  4. Install the driver for the Android device in the virtual machine:
    1. Go to the phone manufacturer’s website, download the latest driver for the phone and install it in the virtual machine.
    2. Make sure that the Android device is displayed correctly in the Device Manager. Windows might also automatically install some driver but that’s not enough.
  5. Connect the Android device in the virtual machine:
    1. In VMWare Player, go to the menu Player -> Removable devices: the Android device should be listed here.
    2. Go to the Android device and select the menu item Connect.
  6. Run the Android app on the device:
    1. Go to Android Studio and press “Run app”: the “Choose device” dialog should list the connected Android device under “Choose a running device”.
    2. Select “Choose a running device”, if not already selected, and select the connected device.
    3. Check “Use same device for future launches”, if you don’t want this dialog to pop up every time you run the app. This way Android Studio will automatically open the app on the connected device.
    4. Click OK.
  7. That’s it! You should see your Android app running on your connected device.

2 thoughts on “How to run an Android app on a device from a virtual machine

  1. Hi, i’ve problem with Android Studio in virtual Machine about emulation, i’ve this error “VT not supported”.
    I’ve enabled VIT in my host computer bios and in vmplayer machine i’ve choose in hardwaer->processors->prederred mode : Intel VT-x. can you help me?

  2. Getting the emulator to work in the virtual machine was tricky for me as well. I eventually just used an Android device.

    The steps that you describe seem correct. I guess your computer has an Intel processor since you can enable VT.

    You can nevertheless double-check the capabilities of your system with the Intel Processor Identification Utility: http://www.intel.com/support/processors/tools/piu/sb/CS-014921.htm
    Intel Virtualization Technology and Intel VT-x should be enabled so that your system fully supports IVT.

    Also Hypervisor and IVT are not compatible! If one is turned on the other must be turned off, Hypervisor is by default on. More on this here: http://www.codeproject.com/Articles/803935/How-To-Make-Android-Studio-Really-Fast-On-A-Window (see step 1)

    Also in that Code Project link, it sounds like you already did step 2 but what about step 3? Did you install the HAXM driver? I recommend reinstalling it: https://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-windows

    Let me know if this helped or if you have any other questions or problems. I am happy to help. 😉

Comments are closed.