Android emulator on Azure VMEverton ReisBlockedUnblockFollowFollowingJun 13There are many different reasons to run an Android emulator, some of them are: app automation, app scraping, or play some cool games xD.
As a Data Scientist, one can be particularly interested in app scraping, and that was my initial motivation to start this journey.
When I tried things on my PC, everything worked fine, but I did not want them running on my machine, and tried to make them work on the cloud.
That was when things started to go badly…The first problem when you try to run an emulator on a Virtual Machine (VM) is that you are trying to run a VM inside another VM and it was not possible, until July 2017, when Azure launched Nested Virtualization for their Dv3 or Ev3 series.
Quoting them:“ Now not only you can create a Hyper-V container with Docker, but also by running nested virtualization, you can create a VM inside a VM.
Such nested environment provides great flexibility in supporting your needs in various areas such as development, testing, customer training, demo, etc.
”I was excited about this possibility and for two days, that was what happened:I did not found a step by step guide on how to make it work, so that is why I decided to write this post, to help other people save their time and avoid pain.
In this article you will learn how to create a VM and run an Android Emulator on it.
I used Nox.
Disclaimer: I am a Data Scientist, not a Data Engineer, so maybe it is not the best way of doing that, but it is the way I find out.
I would be happy to listen to better ideas.
So, let’s work.
The first thing that you need to do, is to create a VM on Azure that supports Nested Virtualization (not all regions support these machine).
I chose US East and the cheapeast option:Create a new resource group, or select an existing one, name your machine and create a username and password:To connect to your machine, you need to enable some inbound port rules:The connection is done through the RDP port.
After that, you can click on “Review + create”, check if everything is ok and Create it.
After some minutes, the deployment will be completed and you can go to the resource.
To connect to your new VM, you can Click on Connect and Download the RDP File, or use some toolbox for remote computing.
I like to use MobaXterm.
Create a new session, choose RDP and enter your remote host IP and Username:The Remote host is the field “Public IP address”, and the Username is the one that you chose when creating the VM.
You can connect to your session by double clicking on it and entering your password.
The first thing that we will do, is to enable Hyper-V on Azure VM.
There is a Microsoft article teaching how to do this.
The easiest way, is to use a PowerShell script to configure it out for you.
It is available here.
Download the NVMBootstrap_WinServer16.
ps1 and execute it:It will check if your VM supports nested virtualization, do what it needs to do and restart the machine.
Login to it again.
Next, let’s install android studio to get some developer functionalities, like Android Debug Bridge (ADB) that will be needed to connect to the emulator.
After concluding the download, let’s install it.
There is nothing special about it, just keep defaults:It will take a while to finish.
When it is finished, you can start it.
And follow these steps:Here is a very important part:Have you ever seen this image:On a white screen???.I don’t think so, that’s why I go for Darcula!Just kidding, it does not make any difference at all, take your preference.
Next, it will download and install some important SDK components:It will automatically install HAXM.
Now let’s download Nox.
And try to install it…Oh my… it strikes again.
Our VM does not have a GPU, so we have problems with OpenGL that is used by the emulator.
If you try to create an emulator with Android, you will face a similar issue:After some investigation, I found out this discussion on StackOverflow that worked for me.
The suggestion was to build a Mesa3D+LLvmpip version of opengl32.
It is an open-source implementation of the OpenGL specification — a system for rendering interactive 3D graphics.
To do that, I followed the excellent tutorial made by Federico Dossena.
You can try to do it by yourself, but it take a while and it is a lot of work, so you can download it from my Github.
After that, there are two options to update de .
dll:1 — Replace the file on windows folder;2 — Rename the file to mesadrv.
dll and change registry, as proposed here.
I chose the first option.
With my opengl32.
dll in hands, I went to C:WindowsSystem32 and make a backup of original opengl32.
dll, and another one for folder C:WindowsSysWOW64.
If you just try to replace the file, you will get a permission error:So, it is necessary to edit file’s permission.
You can do that easily, going on file’s property > Security and click on Advanced.
Change the Owner:Type your username and click on Check Names:After that, confirm everything and close Properties.
Open Properties > Security again, and now you will be able to add your user to the “Group or user names:” box.
Click on Edit > Add and type in the box your user name, as before:Select your user, and allow Full control:You will need to do that on both folders, i.
, C:WindowsSystem32 and C:WindowsSysWOW64.
Now you can paste the new opengl32.
dllIf you try to install Nox now, the error will not appear:Choose Custom and modify D: to C:, otherwise, when you deallocate your VM you will lose the program.
Then, click on install.
When it is ready, it will appear:If you try to start it directly, it will not work….
again:Click on OK, go to Multi-Drive, click on System Settings, and change from OpenGL to DirectX, save changes and close settings.
Try to launch it again:You can start celebrating!Some additional configuration that you need to do, enable Root on System settings:On Android Settings, go to “About tablet” and frenetically click on Build number, it will enable “developer options”.
Restart Nox, so Root modification will make effect, and come back to Developer options and enable USB debugging:So let’s connect to it through ADB.
To do that, first, let’s configure some environment variables.
Open PC properties:Click on Advanced system settings:Click on Environment VariablesCreate a new variable called ANDROID_HOME and point to the folder where Android SDKs are installed, that are on C:Users<your user name>AppDataLocalAndroidSdkYou will probably not see this folder, because it is hidden.
Unhide then doing the following:and create the variable:Now, double click your Path variable and add the following variables:Confirm and close everything.
Open a cmd and try to execute the command adb:If you see all these options, your variables path are ok.
To connect to Nox, use the following command:We are connected!Now we can start our APP scraping, but it is a subject for another publication… If you would like to know how to do that, please tell me in the comments.