Run Android emulator and Android Studio on Azure VM using Hyper V
14 min to read.
Due to Corona outbreak, times are hard! Please take care
everyone! I wish good health for all! Stay safe!
There is another outbreak I am seeing – Making
Development environment available on Azure to enable Work from home. Almost in
every customer call I hear about requirement to enable Development Environment
on Azure and accessing it from Home laptop/ PC and continue the business.
In the era of “Mobile first” almost every big
enterprise, every Small and Medium Business (SMB), every Start up company have
mobile development teams. They use variety of tools and one of the important
IDE used for Mobile development is “Android Studio”.
Installing and running Android studio is smooth; however
Android emulator installation fails on Azure VM. It is not s07aight forward. In
this blog we will see “how to enable Android emulator with Android Studio on
Azure VM”.
Let’s go!
Without a virtualization technology and VM acceleration,
the Android emulator must 07anslate the machine code from the VM block by block
to conform to the architecture of the host computer. This process can be quite
slow.
With a hypervisor, the VM and the architecture of the computer running
emulator match, so the emulator can run code directly on the processor using
the hypervisor. This improvement drastically increases both the speed and
performance of the android emulator.
This concept is well suited for hardware. For example,
if you have laptop then Android emulator can work like a charm. Because the
required hardware for VM acceleration is provided by underlying laptop on which
you are running Android Studio and hypervisor for emulator runs on laptop
hardware.
Android emulator is default based on Intel Hardware
Accelerated Execution manager [HAXM]. This is Virtualization technology used
behind the scene by Android studio to run the android emulator. HAXM is
installed as a part of installation process of Android Studio as well.
So on Azure VM where we plan to run the Android
simulator, Intel HAXM should be installed and present.
At the same time Intel HAXM and Hyper V are mutually
exclusive. Means, if you have Hyper V enabled then HAXM can’t be installed and
vice versa.
Installation of HAXM on Azure VM is not a problem. The
VM series is a problem. When you say I want to install the HAXM; Hyper V should
be disabled. Most of the VM series today have Hyper V “some way” enabled or not
supported.
Remember Azure VM itself is a VM. Means it is based on
Hyper V behind the scene already. Now on top of this VM you want to install
another Hypervisor – either HAXM or Hyper V. The only series that supports the
Hyper V on Azure VM itself is Hyperthreaded VMs – Dsv3 and Esv3 series or Dv3
and Ev3 series.
This Azure VM series support nested virtualization;
because it supports running Hyper V on top of it or running any other hypervisor
on top of it. Therefore installation of HAXM on Azure VM will succeed only on
these Azure VMs and other will fail.
Now even if we install HAXM successfully on Azure VM and
then install Android Studio with emulator successfully; the emulator will not
work. I have experienced many errors as described below -
“error while
loading state for instance 0x0 of device 'goldfish_pipe'”.
“Unfortunately, the Android emulator can’t support
virtual machine acceleration from within a virtual machine.”
Microsoft Visual Studio has Android Emulator. It uses
WHPX technology behind the scene. However it works on hardware. Means it can
run well on your laptop but not on Azure VM. I could not start Android Emulator
on Azure VM. When I attach the Visual Studio Android Emulator to Android
Studio; it fails with many errors.
So what is the solution?
Well, the solution provided will not help to
run the latest version of Android emulator. However you will be able to make
the Android Emulator work on Azure VM with “Older version”.
For this we will leverage “VS Emulator for Android”
which is earlier version of Android Emulator Microsoft had released prior to
current version of “hardware acceleration” based Android emulator.
So overall solution looks as follow – [click to get better view].
As a part of the solution make sure you provision VM
with v3 series. I have selected Ds4v3 VM on Azure portal and provisioned it. By
default allow the internet access to this VM so that we can download required
software. As per the diagram I have attached public IP to my VM. So take RDP
over public IP.
After RDP, install the software in the order mentioned
below.
I have selected below version [click to get better view]
of Windows 10 for provisioning VM on Azure. Also I have selected Ds4v3 series and
Gen1 for provisioning. Go ahead and provision Azure VM.
Install Hyper V
Login to your VM and configure Hyper V on top of it. Open
Run window -> type “appwiz.cpl” -> Click on “Turn windows feature on or off”
-> Select all options against Hyper V option -> Select option “Windows
Hypervisor platform”. After successful installation restart VM. Refer below
[click to get better view].
Install Java
Restart the machine.
Install Visual Studio Emulator for Android
Go to this page - https://visualstudio.microsoft.com/vs/msft-android-emulator/.
Install VS emulator for Android. Remember we don’t have to install the complete
Visual Studio here. The Visual Studio based Android emulator is based on
Hardware acceleration and it will not work on Azure VM. At least I could not
make it work after lot of attempts.
Successful installation screen shown below. It should
also appear in start menu. [click to get better view].
After installation restart the Azure VM.
Install Android Studio
Install Android Studio from the link - https://developer.android.com/studio#downloads.
Current version as of today is Android Studio 3.6.3. Install with default
selected options. After successful installation you will see an option “start
android studio”. Select this option and click finish as shown [click to get
better view].
This launches the Android Studio and further starts
configuration of Android Emulator. Continue with standard configuration with
default options selected. You will see that HAXM installation failed. This is
expected behavior as Hyper V is already enabled; HAXM is bound to fail. You
will get screenshot as follows [click to get better view] –
This completes the installation of all required software. Restart the machine.
The default path of Android SDK for me is - C:\Users\kunal\AppData\Local\Android\Sdk.
This is default path.
Comments
Post a Comment