Let's Mod: Chromium for Android

Let's Mod: Chromium for Android

In this article, learn how to setup the build environment and design your first copy of Chromium

What's Let's Mod about?

Let's Mod is a series of articles where we go about modding some of our favourite open-source softwares that we use on a daily basis.

In the first segment of the series, we will be looking into one of the most widely used open-source products- The Chromium Project. Chromium makes up for over 80% of the market share and in comes in various formats with Google Chrome being the biggest Chromium-based product amounting to 77.08% of browser market share. There is also a possibility that the browser that you are viewing this article on is also a Chromium-based browser considering its popularity.

Here are some Chromium-based browsers:

  • Google Chrome
  • Microsoft Edge
  • Brave Browser
  • Opera
  • Bromite browser
  • Android System WebView (Trichrome and monochrome libraries)

In this article, we will learn how to set up the build environment, clone the browser code and design an initial build.

Prerequisite:

  • At least 100GB of spare storage
  • At least 16GB ram anything
  • Linux is highly preferred and Google's recommended operating system-package is Ubuntu
  • Git and Python to bepre-installed
  • 4 cores 4 threaded CPU is a minimum (an 8 core 16 thread is ideal for any light mod as this can significantly reduce your build times)

Let's get coding

  • To start off install the required depot tools. This installs a set of tools required to pull and build the code. Run the following code to proceed:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:/path/to/depot_tools"
  • To retrieve the code, run the following snippet:
mkdir ~/chromium && cd ~/chromium
fetch --nohooks chromium
  • If you don't want the full repo history, you can save a lot of time by adding the --no-history flag to fetch. Expect the command to take thirty minutes even on a fast connection and many long hours on slower ones.
  • When fetch completes, it will have created a hidden .gclient file and a directory called src in the working directory. Run the following code to proceed:
cd src
  • You can add Android support by appending target_os = ['android'] to your .gclient file (in the directory above src). Run the following code to proceed:
echo "target_os = [ 'android' ]" >> ../.gclient

Then run gclient sync to pull the new Android dependencies:

gclient sync
  • You can also install additional build dependencies by running the following code:
build/install-build-deps-android.sh
  • This will get you all of the dependencies you need to build on Linux along with the Android-specific dependencies (you need some of the regular Linux dependencies because an Android build includes Linux tools and utilities).
  • Once you've run install-build-deps at least once, you can now run Chromium-specific hooks which will download additional binaries and other things you might need. Run the following code to proceed:
gclient runhooks
  • Chromium uses Ninja as its main build tool along with a tool called GN to generate .ninja files. You can create any number of build directories with different configurations with these functionalities. To create a build directory that builds Chrome for Android, run gn args out/Default and edit the file to contain the following arguments:
target_os = "android"
target_cpu = "arm64"

NOTE: You only have to run this once for each new build directory, Ninja will update the build files as needed. You can replace Default with another name, but it should be a subdirectory of out. For other build arguments including release settings, see GN build configuration. The default will be a debug component build. For more info on GN, run gn help on the command line or read the quick start guide.

Also be aware that some scripts (e.g. tombstones.py, adb_gdb.py) require you to set CHROMIUM_OUTPUT_DIR=out/Default.

Build Chromium

To create the final build for Chromium, run the following code:

autoninja -C out/Default chrome_public_apk

(autoninja is a wrapper that automatically provides optimal values for the arguments passed to ninja.)

  • You can get a list of all of the other build targets from GN by running gn ls out/Default from the command line. To compile, pass the GN label to Ninja with no preceding “//” (this is expressly for //chrome/test:unit_tests``` use ```autoninja -C out/Default chrome/test:unit_tests).

Installing and running Chromium on a device

  • Make sure your Android device is plugged in via USB, and USB Debugging is enabled.
  • Next, check the connected devices by running the following code:
    adb devices
    
  • After checking the devices, you can enable apps from unknown sources by running the following code:
    adb shell settings put global verifier_verify_adb_installs 0
    
  • Lastly, deploy your build to the preferred device by running the following code:
    out/Default/bin/chrome_public_apk install
    

    Conclusion

After having executed all the instructions given in this article, you should be having a ready to use build in your hand in around 8 to 10 hours of time provided you have a 4 core 8 thread CPU with 16GB of RAM. In the coming articles of the same series, we will discuss logging in code, debugging the build etc. We will also look into adding some new exciting features to your browser as well while modding the browser to enhance its build. Gear up to showcase your own flavour of Chromium browser by the end of this series! Hope to see you soon!