Android Emulator Windows Development

This document describes how to get started with emulator development under windows. If you want to use your own machine you can skip the sections on cloud an gWindows.

Developing on gWindows

This section is only relevant if you work at Google. Be warned, gWindows can cause all sorts of unexpected issues, if at all possible do not use a gWindows machine.

In order to develop the android emulator in gWindows you will need to meet the following requirements:

  • Have a bit9 exception http://go/bit9
  • Exception for credential guard http://go/winops-credential-guard (if you want to use haxm)
  • Have admin privileges on your machine.
  • A Compiler toolchain to compile the sources. Any edition of Visual Studio 2019 is known to work

Note: The gWindows machines are locked down very well and you will experience some performance penalties due to this. You are highly encouraged to develop in GCE or use an offcorp machine

Developing in GCE

This section is only relevant if you want to setup a development environment in google cloud.

First we need to create a Windows image with nested virtualization enabled:

Note: this is not officially supported, but we have not seen any issues.

  $ WIN_VER=windows-2012-r2 && ZONE=us-west1-b &&
   gcloud compute disks create nested-$WIN_VER \
    --image-project=windows-cloud \
    --image-family $WIN_VER \
    --zone $ZONE \
    --size 500GB
    --licenses "" &&
   gcloud compute images create nested-$WIN_VER-image \
    --source-disk nested-$WIN_VER \
    --source-disk-zone $ZONE \
    --licenses ""

You can change the family to the latest windows version, and of course set the zone and disk size to your liking. Do not pick a core edition, as you will want to have a shell.

Next we create an instance and install all the necessary things

    $ gcloud compute instances create  \
      $USER-windows-development-01 \
      --zone $ZONE \
      --min-cpu-platform "Intel Haswell" \
      --image nested-$WIN_VER

You will need to setup the password, after which you should be able to login.

     gcloud beta compute reset-windows-password \
     $USER-windows-development-01  \

Software Requirements

Install the following:

  • Visual Studio 2019. We will need the compiler toolchain with the latest windows sdk, as we need the WHPX headers. Make sure to install the following set of tools:
    • Visual C++ build tools
    • Visual C++ ATL for x86 & x64
    • Visual C++ MFC for x86 & x64
    • Windows 10 SDK (10.0.19041.0)
  • Git. Make sure that the install updates your path, so git will be on the path.
  • Python3. Needed for repo.
  • VScode Visual studio code works well for emulator development. Make sure to install the at least following extensions:
  • Add %USERPROFILE%\bin to the path.
  • Rust The Rust compiler toolchain. You must install a rust toolchain that has support for the target: x86_64-pc-windows-msvc (default if you install from the link). If this target is not present you will see many failures.

If you are using Chocolatey, you can install all the dependencies with the following command in an elevated terminal window (i.e. type Win-R key then type “cmd”):

C:\>@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString(''))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

choco install -y visualstudio2019community visualstudio2019buildtools visualstudio2019-workload-python curl visualstudio2019-workload-nativedesktop visualstudio2019-workload-vctools visualstudio2022-workload-python git vscode python3

You must run visual studio at least once to accept a license and do some initial configuration.

Make sure your account has SeCreateSymbolicLinkPrivilege. The easiest way to make sure you have this is to open every terminal window with administrator privileges.

Once you have installed everything you can validate that you have what you need on the path by executing:

C:\> where git && where python

Configure git

You will need to setup your name and make sure you enable symlinks. Repo will do its best to work without symlinks enabled, but we have not tested this. Make sure you have the following settings set:

C:\> git config --system core.symlinks true
C:\> git config --global core.symlinks true
C:\> git config --global "I just copy pasted this without looking"
C:\> git config --global

Obtaining repo for windows

Note: The instructions in this section are for using the native Windows version of the repo tool, where “native” is used to mean without “cygwin”.

There are 2 advantages running with Windows native tools:

  • Improved performance. For example, Git for Windows is usually dramatically faster the git for cygwin for many common operations
  • Compatibility with other native Windows tools: e.g. cmd.exe, TortoiseGit, IntelliJ, etc.

From an elevated command prompt execute:

mkdir %USERPROFILE%\bin && cd %USERPROFILE%\bin && curl -o repo && echo @call python %~dp0repo %* > %USERPROFILE%/bin/repo.cmd

Make sure to add %USERPROFILE%\bin to the PATH, otherwise you will not be able to use repo.

Initialize the repository

You can initialize repo as follows:

cd %USERPROFILE%\src && mkdir emu-master-dev && cd emu-master-dev
repo init -u -b emu-master-dev

Note: we are not using persistent-https to initialize the repo, this means performance will not be as good as it could be

Sync the repo and get some coffee.

   cd %USERPROFILE%\src\emu-master-dev && repo sync --no-tags --optimized-fetch --prune

Congratulations! You have all the sources you need. Now run:

   cd %USERPROFILE%\src\emu-master-dev\external\qemu && android\rebuild

You should end up with an emulator in the objs directory.

You can pass the flag --help to the rebuild script to get an idea of which options you can pass in.

Setup git cookies

Setup git cookies so you can repo upload by following this link:

Make sure you have configured the proper user name and email address:

  C:\>git config --global "I just copy pasted this without looking"
  C:\>git config --global

Here you can find more details on submitting patches.

Known Issues

I can't compile under visual studio code

Our cmake files rely on the visual studio environment variables to be set as they are used to properly configure the compiler toolchain. The easiest workaround is to start visual studio code from the command line after loading the visual studio variables. Look for the line: Accepted, setting env with in the output from rebuild.cmd.

Where do I obtain avds etc?

The easiest way to get started is to install android studio:

  choco install androidstudio

Next you can launch android studio and install a series of avds that you can use