Building several Google open source projects (Android, Chromium, ChromiumOS)

Building several Google open source projects (Android, Chromium, ChromiumOS)

2nd January 2019 0 By darryncampbell

Working for an Android OEM I get frequent questions about Android open source and the Chromium project, so I thought I would gain some practical experience building some of the popular Google open source projects for myself.

I had a couple of projects on my radar:

  • The Android Open Source project, i.e. that component of Android which does not depend on Google’s closed source services.
  • Chromium, the underlying web rendering engine for Chrome (and more recently, Edge)
    • I wanted to build this for both the desktop and Android.
  • Chromium OS, the open source components underpinning Google’s Chrome OS

The hardware

Whilst building a dedicated machine for building open source projects would be fun, I would struggle to justify the expense to IT so I fell back on my everyday development machine which is by now about 5 years old! An Intel Xeon (2.80GHz) with 4 cores and 32GB of RAM.  Well specified for RAM but lacking in processing power so builds would be a bit slow.

My development machine has Windows installed so my instinct was to try building in a Virtual Machine, especially given the machine’s healthy RAM.  I would not recommend this for anybody else building these projects, primarily because getting an emulator running within a VM was not simple and required some tweaking… I did not manage to solve the issue before giving up on the Virtual Machine approach and instead reaching for an old, mechanical 1TB hard drive.  I replaced my machine’s existing HDD with this old drive which, whilst mechanical (slow), had enough space to build all the projects without having to span multiple disks and was a simple swap-in replacement to my existing setup.

The software

I settled on building with Ubuntu 14.04 which, whilst old (2015), is called out explicitly by the AOSP build requirements.  I would need to update my version of Ubuntu to 16.04 before I was able to successfully run the Android emulator – this is still not the latest LTS release but it was the version offered by the internal updater so I just ran with it.  I would recommend using the latest LTS release of Ubuntu to build these projects but I’ll call out explicitly which version I used for each project.

Building the Android Open Source project

All the downloading and building steps detailed in https://source.android.com/setup/build/downloading worked without issue on both Ubuntu variants I tried (14.04 and 16.04).

As I previously mentioned, I had difficulty getting the Android emulator to work within a Virtual Machine – I would recommend not even trying this approach, although it is probably possible, it is far easier to jump straight to building on metal.  Having abandoned the VM approach, trying to run the emulator with Ubuntu 14.04 gave me a cryptic warning about ‘FT_Get_Font_Format’ with nothing relevant on Stack Overflow.  After updating my Ubuntu version to 16.04 the emulator would now launch but would crash the machine after several seconds of running.  This new issue DID have some helpful answer on Stack Overflow and after running with the -gpu off flag, everything worked well.

So, to be clear, following the instructions at https://source.android.com/setup/build/building on Ubuntu 16.04 and specifying lunch lunch aosp_x86_64-eng successfully built an x86 emulator image which I was then able to run with the emulator -gpu off command on bare metal.

AOSP master branch in an x86 emulator

AOSP master branch in an x86 emulator – Android Q

System applications (e.g. calculator, Email, Gallery) are built under ~/WORKING_DIRECTORY/out/target/product/generic_x86_64/system/app but bear in mind these are x86 applications so you could not just install them on your arm phone and would need to instead compile them for Arm.

Building Chromium

Before targeting Chromium Android, I started off by following the Chromium build instructions for Linux, these worked well on both Ubuntu 14.04 and 16.04.  I did start building within an emulator and I think it would have worked but I moved onto building directly on bare metal before I gave it a chance to finish.

The only issue I had building Chromium was the inordinate amount of time the build took which was somewhere around 12 hours for the build phase – this was about twice as long as it took to build AOSP on my (admittedly underspecified) machine but still, this made things quite time consuming.

Still building for the desktop, I also tried targeting a specific git tag (73.0.3654.1) using the instructions given in the project page.  Again, the software built without issue following my git checkout tags/73.0.3654.1 command.

Since I kept the builds separate, I now had two versions of Chromium built, 73.0.3654.1 (the tag) and 73.0.3657.0 (the latest at the time of writing).  You can’t run these both at the same time on the same machine but running them individually you can see the version difference.

Building desktop Chromium against the master branch (at the time of writing)
Building desktop Chromium against a specific tag

There was a step I missed related to obtaining Google API keys to access specific services; the build instructions stated this was optional so I omitted it for reasons of time but doing so did give me a warning on launch:

Warning if you omit obtaining Google API keys during the build step

Building Chromium for Android

Given the success of building Chromium for the desktop, I moved onto building Chromium for Android.  I opted for a clean build directory rather than trying to convert my existing desktop build, purely because I thought I might want to return to my desktop build at some stage.

I initially built with Ubuntu 14.04 and had to uninstall the unity-control-center package before the build would complete.  I suspect that had I built with Ubuntu 16.04 from the start then I would not have had this issue, but it is worth mentioning.

The Chromium apk is output to ~/chromium_android/src/out/Default/apks but since this is built for arm, I could not run it on the x86 emulator I created in the previous step… I could of course run it on a physical device (in this case, a Zebra TC57):

Chromium installed on a physical device (icon)
Chromium running on a physical device (application)

Although I did not try to build Chromium for Android within a Virtual Machine, I suspect it would have worked.

Building ChromiumOS

The steps for building ChromiumOS are the most detailed and are very easy to follow.  Originally, when building on a Virtual Machine I got an error saying my system was not configured correctly (when building packages) however later I realised this was probably because I missed the step to “verify that your default file permissions (umask) setting is correct”.  Regardless, I gave up on the Virtual Machine approach and moved to building directly on bare metal instead with Ubuntu 16.04 – since I wanted to run ChromiumOS within its own emulator this was probably a sensible choice.

The ‘download packages’ step occasionally felt like it got stuck but it eventually succeeded.  All the building steps succeeded, targeting the arm64-generic board.  Since I don’t have a Chromebook handy I wanted to target a Virtual Machine but be aware that when building the disk image, do not specify a test build (this instruction appears much later in the document, only after it previously told you to build a test image!).

(inside choot)
./build_image --board=arm64-generic –noenable_rootfs_verification  

Then you will be able to successfully follow the instructions to build (convert) the image to run in a virtual machine (./image_to_vm.sh –board=amd64-generic).  After running this script the command line will tell you how to start the VM, in my case it was:

cros_vm --start
--image-path /mnt/host/source/src/build/images/amd64-generic/R73-11496.0.2018_12_31_0742-a1/chromiumos_qemu_image.bin

I had previously installed KVM on my machine (though I’m not 100% sure if this was necessary) and I was then able to use Vinagre to connect to the VNC server and see the running VM:

ChromiumOS running within a Virtual Machine on Linux

Conclusion

In conclusion, all 3 projects I tried I could get building successfully without too much hassle – the only problem I found with documentation was the red herring that initially pointed me towards Ubuntu 14.04 and I wish I had just started on the latest LTS Ubuntu release.  Although using a VM felt like the easiest approach to start with, I would definitely recommend building on real hardware if possible and I think my approach of just putting a new HDD in your most powerful machine is probably a good approach for Windows users like myself.