tree: 34c3e1a5eb535096975ed46db2fc2ac50651defb [path history] [tgz]
  1. .clang-tidy
  2. .dir-locals.el
  3. .editorconfig
  4. .exrc
  5. .gdbinit
  6. .gitattributes
  7. .gitignore
  8. .gitmodules
  9. .gitpublish
  10. .mailmap
  11. .shippable.yml
  12. .travis.yml
  13. .vscode/
  14. CMakeLists.txt
  15. CODING_STYLE
  16. COPYING
  17. COPYING.LIB
  18. COPYING.PYTHON
  19. Changelog
  20. GNUmakefile
  21. HACKING
  22. LICENSE
  23. LICENSES/
  24. MAINTAINERS
  25. MODULE_LICENSE_GPL
  26. Makefile
  27. Makefile.objs
  28. Makefile.target
  29. NOTICE
  30. QEMU_VERSION
  31. README
  32. README.md
  33. accel/
  34. android-info.txt
  35. android-qemu2-glue/
  36. android/
  37. arch_init.c
  38. audio/
  39. backends/
  40. balloon.c
  41. block.c
  42. block/
  43. blockdev-nbd.c
  44. blockdev.c
  45. blockjob.c
  46. bootdevice.c
  47. bsd-user/
  48. bt-host.c
  49. bt-vhci.c
  50. build-kicker.txt
  51. build.gradle
  52. chardev/
  53. cmake-format.json
  54. cmake-main.darwin-aarch64.inc
  55. cmake-main.darwin-x86_64.inc
  56. cmake-main.linux-aarch64.inc
  57. cmake-main.linux-x86_64.inc
  58. cmake-main.windows_msvc-x86_64.inc
  59. configure
  60. contrib/
  61. cpus-common.c
  62. cpus.c
  63. crypto/
  64. default-configs/
  65. device-hotplug.c
  66. device_tree.c
  67. disas.c
  68. disas/
  69. dma-helpers.c
  70. docs/
  71. dummy.c
  72. dump.c
  73. entitlements.plist
  74. exec.c
  75. filelist
  76. fpu/
  77. fsdev/
  78. gdb-xml/
  79. gdbstub.c
  80. hmp-commands-info.hx
  81. hmp-commands.hx
  82. hmp.c
  83. hmp.h
  84. hvf-stub.c
  85. hw/
  86. include/
  87. io/
  88. ioport.c
  89. iothread.c
  90. libdecnumber/
  91. linux-headers/
  92. linux-user/
  93. mac.source.properties
  94. memory.c
  95. memory_ldst.inc.c
  96. memory_mapping.c
  97. migration/
  98. module-common.c
  99. monitor.c
  100. nbd/
  101. net/
  102. numa.c
  103. os-posix.c
  104. os-win32.c
  105. pc-bios/
  106. po/
  107. qapi/
  108. qdev-monitor.c
  109. qdict-test-data.txt
  110. qemu-bridge-helper.c
  111. qemu-char.c
  112. qemu-doc.texi
  113. qemu-ga.texi
  114. qemu-img-cmds.hx
  115. qemu-img.c
  116. qemu-img.texi
  117. qemu-io-cmds.c
  118. qemu-io.c
  119. qemu-keymap.c
  120. qemu-nbd.c
  121. qemu-nbd.texi
  122. qemu-option-trace.texi
  123. qemu-options-wrapper.h
  124. qemu-options.def
  125. qemu-options.h
  126. qemu-options.hx
  127. qemu-seccomp.c
  128. qemu-tech.texi
  129. qemu-test.cmake
  130. qemu-version.h.in
  131. qemu.nsi
  132. qemu.sasl
  133. qemu2-auto-generated/
  134. qga/
  135. qmp.c
  136. qobject/
  137. qom/
  138. qtest.c
  139. replay/
  140. replication.c
  141. replication.h
  142. roms/
  143. rules.mak
  144. scripts/
  145. scsi/
  146. sign-objs-binaries.sh
  147. sign-vm-entitlement.sh
  148. slirp/
  149. source.properties
  150. stubs/
  151. target/
  152. tcg/
  153. tests/
  154. thunk.c
  155. tpm.c
  156. trace-events
  157. trace/
  158. ui/
  159. util/
  160. version.rc
  161. vl.c
  162. whpx-stub.c
  163. win.source.properties
README.md

Welcome to the Android Emulator

This document gives you some background on the emulator and outlines how you can start hacking and contributing to the emulator!

Just get me started with development!

Make sure to install Android Studio and the associated SDKs. Do not forget to install the official emulator and create a few android virtual devices. Next follow the instructions for the platform you would like to work on:

We use the Repo tool to manage working accross multiple branches.

About the Emulator

The Android Emulator simulates Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have each physical device.

The emulator provides almost all of the capabilities of a real Android device. You can simulate incoming phone calls and text messages, specify the location of the device, simulate different network speeds, simulate rotation and other hardware sensors, access the Google Play Store, and much more.

Testing your app on the emulator is in some ways faster and easier than doing so on a physical device. For example, you can transfer data faster to the emulator than to a device connected over USB.

The emulator comes with predefined configurations for various Android phone, tablet, Wear OS, and Android TV devices.

Recommended Reading

The following is a list of concepts that are important. Please read these links and any other links you can find. If you find a link that you think does a better job at explaining the concept, please add it here:

QEMU is an open source competitor to VMware Workstation, VirtualBox, HyperV. It is focused on Linux server virtualization on Linux servers. While QEMU does support booting other OS’s, we don’t use that functionality since Android is Linux.

The Android Emulator is downstream from the QEMU emulator. It adds support for booting Android devices, emulates typical Android hardware (OpenGL, GPS, GSM, Sensors) and a GUI interface. The android emulator extends qemu in various ways.

For an overview of Qemu see:

The QEMU emulator leverages technologies like hardware Hypervisors KVM (Linux) and HAXM (Windows/Mac)

https://en.wikipedia.org/wiki/Hypervisor https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine

The QEMU emulator supports both guest images that require full virtualization and guest images that require paravirtualization technologies like virtio

The emulator passes a device tree blob to a guest kernel to describe the guest hardware

When running a non-x86 image on an x86 host, QEMU will JIT the non-x86 code into x86 code. See this lectutre for more. The MMU (page table hardware) is emulated in software, which is unfortunately slow.

You will need to build Android kernels and system images that the emulator will run. The easiest way to obtain these is to make use of the publicly released images. You can find more details here.

Building the Emulator

The emulator uses Cmake as a meta build generator, and all the necessary compilers and toolchains are included in the repository. Make sure you have read the section above as the requirements to succesfully build vary slightly from platform to platform.

In general you can run the following script:

./android/rebuild.sh

For incremental builds you can use ninja. For example

ninja -C objs

Contributing code

The emulator uses a coding style derived from the Chromium style. We use the repo tool to submit pathces. The usual workflow is roughly as follows:

    repy sync # Pulls in all the changes accross all branches.
    repo start my_awesome_feature

This will create a git branch called my_awesome_feature. You can now work on your patch.

Once you have written a patch you can send it out for code review. We use gerrit for code reviews.

Use the repo tool to upload or update a CL:

    repo upload --cbr --re=”blah@google.com,foo@google.com,bar@google.com
  • “--cbr” means “upload the current branch”,
  • “--re” supplies the initial reviewers list

Add “-t” switch to use the current git branch as a review topic (topic groups CLs together and only allows them to be submitted when all got +2/+verified)

The repo tool will provide you with a url where you can find your change.

Code Reviews

Make sure to check the CL against our coding style: coding style. Coding style isn’t frozen: just edit it in our repository and create a code review to propose a change.

Some good articles on code reviewing, especially when it comes to google:

Below are some short notes relevant to the emulator.

Keep in mind that all of the code reviews are open source and visible to everyone!. In other words, be nice and and provide actionable constructive feedback.

  • C++ over C for all new code. Always.

  • After uploading a CL for review, author should “+1” it when they think it’s ready for reviewing. A CL without author’s “+1” is a “work in progress” and other reviewers may ignore it..

  • Prefer not to send a WIP CL to reviewers and only add them when it’s in a reviewable state. If you realized that you added reviewers too soon, just remove them - “x” button in the browser UI for each reviewer actually works.

  • Avoid large CLs. There are always exceptions, use your best judgement to improve code clarity and to help other maintainers in the future.

    Split the changes into smaller isolated chunks and submit those as a single topic If you touch multiple components, that’s a good way to split the CL.

    Changes into any QEMU files must be in their own CL - otherwise rebasing into the new version becomes 10x more painful.

  • “-2” is sticky, it remains there until the very same reviewer removes it. If you “-2”-ed someone, it’s always a good thing to communicate to them about the follow-up

  • Abandon the CLs you don’t need anymore

  • Tests: when reviewing the code, make sure there’s a test or a really good reason for its absence

Merging downstream Qemu

Merging changes from the qemu branch should be done on the emu-master-qemu branch. You will need to this on a linux machine as qemu development happens in a linux environment. Once you have obtained this branch you can add the remote qemu repository as follows:

cd emu-master-qemu/external/qemu
git remote add qemu https://git.qemu.org/git/qemu.git
git fetch qemu

Now you can start merging in changes:

git merge master

Be smart, merge only a few commits at a time

Next you should try to build qemu standalone:

    ./android/scripts/unix/build-qemu-android.sh  --verbose --verbose --build-dir=$HOME/qemu-build  &&
    cd $HOME/qemu-build/build-linux-x86_64 &&
    source env.sh &&
    cd qemu-android &&
    make

Now you are ready for building, testing, and merging the next set. You could have a look at this script to automate this slightly.