There are instructions for other platforms linked from theget the code page.
Are you a Google employee? Seego/building-android-chrome instead.
Most development is done on Ubuntu. Other distros may or may not work; see theLinux instructions for some suggestions.
Building the Android client on Windows or Mac is not supported and doesn't work.
Clone thedepot_tools
repository:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Adddepot_tools
to the end of your PATH (you will probably want to put this in your~/.bashrc
or~/.zshrc
). Assuming you cloneddepot_tools
to/path/to/depot_tools
:
export PATH="$PATH:/path/to/depot_tools"
Create achromium
directory for the checkout and change to it (you can call this whatever you like and put it wherever you like, as long as the full path has no spaces):
mkdir~/chromium && cd ~/chromiumfetch--nohooks android
If you don't want the full repo history, you can save a lot of time by adding the--no-history
flag tofetch
.
Expect the command to take 30 minutes on even a fast connection, and many hours on slower ones.
If you've already installed the build dependencies on the machine (from another checkout, for example), you can omit the--nohooks
flag andfetch
will automatically executegclient runhooks
at the end.
Whenfetch
completes, it will have created a hidden.gclient
file and a directory calledsrc
in the working directory. The remaining instructions assume you have switched to thesrc
directory:
cd src
If you have an existing Linux checkout, you can add Android support by appendingtarget_os = ['linux', 'android']
to your.gclient
file (in the directory abovesrc
):
echo"target_os = [ 'linux', 'android' ]">>../.gclient
Then rungclient sync
to pull the new Android dependencies:
gclient sync
(This is the only difference betweenfetch android
andfetch chromium
.)
Once you have checked out the code, run
build/install-build-deps.sh
to get all of the dependencies you need to build on Linux,plus all of the Android-specific dependencies (you need some of the regular Linux dependencies because an Android build includes a bunch of the Linux tools and utilities).
NOTE: For 32-bit builds, the--lib32
command line switch could be used. You may run into issues wheregperf
orpkgconf
don't get installed, without it. To remedy this, and potentially other missing packages, you will have to install them manually using:
sudo apt-get install{missing_pkg}
Once you've runinstall-build-deps
at least once, you can now run the Chromium-specific hooks, which will download additional binaries and other things you might need:
gclient runhooks
Optional: You can alsoinstall API keys if you want your build to talk to some Google services, but this is not necessary for most development and testing purposes.
Chromium usesSiso as its main build tool along with a tool calledGN to generate.ninja
files. You can create any number ofbuild directories with different configurations. To create a build directory which builds Chrome for Android, rungn args out/Default
and edit the file to contain the following arguments:
target_os="android"target_cpu="arm64"# See "Figuring out target_cpu" belowuse_remoteexec=true# Enables distributed builds. See "Faster Builds".is_component_build=false# Unless you do a lot of native code edits. See "Faster Builds".
Default
with another name, but it should be a subdirectory ofout
.gn help
on the command line or read thequick start guide.Also be aware that some scripts (e.g.tombstones.py
,adb_gdb.py
) require you to setCHROMIUM_OUTPUT_DIR=out/Default
.
The value oftarget_cpu
determines what instruction set to use for native code. Given a device (or emulator), you can determine the correct instruction set withadb shell getprop ro.product.cpu.abi
:
getprop ro.product.cpu.abi output | target_cpu value |
---|---|
arm64-v8a | arm64 |
armeabi-v7a | arm |
x86 | x86 |
x86_64 | x64 |
arm
andx86
may optionally be used instead ofarm64
andx64
for non-WebView targets. This is also allowed for Monochrome, but only when not set as the WebView provider.Build Chromium with Siso or Ninja using the command:
autoninja-Cout/Default chrome_public_apk
(autoninja
is a wrapper that automatically provides optimal values for the arguments passed tosiso
orninja
.)
You can get a list of all of the other build targets from GN by runninggn ls out/Default
from the command line. To compile one, pass the GN label to Ninja with no preceding “//” (so, for//chrome/test:unit_tests
useautoninja -C out/Default chrome/test:unit_tests
).
The Google Play Store allows apps to send customized bundles (.aab
files) depending on the version of Android running on a device. Chrome uses this feature to package optimized versions for different OS versions.
monochrome_public_bundle
(MonochromePublic.aab
)minSdkVersion=26
(Oreo). [Deprecated]trichrome_chrome_bundle
(TrichromeChrome.aab
)minSdkVersion=29
(Android 10).trichrome_library_apk
trichrome_webview_bundle
chrome_public_bundle
&chrome_public_apk
(ChromePublic.aab
,ChromePublic.apk
)minSdkVersion=29
(Android 10).system_webview_bundle
/system_webview_apk
).Notes:
chrome_public_apk
, but any of the other targets can be substituted.To update an existing checkout, you can run
$ git rebase-update$ gclient sync
The first command updates the primary Chromium source repository and rebases any of your local branches on top of tip-of-tree (aka the Git branchorigin/main
). If you don't want to use this script, you can also just usegit pull
or other common Git commands to update the repo.
The second command syncs dependencies to the appropriate versions and re-runs hooks as needed.
Make sure your Android device is plugged in via USB, and USB Debugging is enabled.
To enable USB Debugging:
You may also be prompted to allow access to your PC once your device is plugged in.
You can check if the device is connected by running:
third_party/android_sdk/public/platform-tools/adb devices
Which prints a list of connected devices. If not connected, try unplugging and reattaching your device.
Allow Android to run APKs that haven't been signed through the Play Store:
In case that setting isn't present, it may be possible to configure it viaadb shell
instead:
third_party/android_sdk/public/platform-tools/adb shell settings putglobal verifier_verify_adb_installs0
autoninja-Cout/Default chrome_public_apk
And deploy it to your Android device:
out/Default/bin/chrome_public_apk install
The app will appear on the device as “Chromium”.
Wraps the content module (but not the /chrome embedder). Seehttps://www.chromium.org/developers/content-module for details on the content module and content shell.
autoninja-Cout/Default content_shell_apkout/Default/bin/content_shell_apk install
this will build and install an Android apk underout/Default/apks/ContentShell.apk
.
Android WebView is a system framework component. Since Android KitKat, it is implemented using Chromium code (based off thecontent module).
If you want to build the complete Android WebView framework component and test the effect of your chromium changes in Android apps using WebView, you should follow theAndroid AOSP + chromium WebView instructions
For Content shell:
out/Default/bin/content_shell_apk launch[--args='--foo --bar'] http://example.com
For Chrome public:
out/Default/bin/chrome_public_apk launch[--args='--foo --bar'] http://example.com
Logging is often the easiest way to understand code flow. In C++ you can print log statements using the LOG macro. In Java, refer toandroid_logging.md.
You can see these log viaadb logcat
, or:
out/Default/bin/chrome_public_apk logcat
Logcat supports an additional feature of filtering and highlighting user-defined patterns. To use this mechanism, define a shell variable:CHROMIUM_LOGCAT_HIGHLIGHT
and assign your desired pattern. The pattern will be used to search for any substring (ie. no need to prefix or suffix it with.*
), eg:
export CHROMIUM_LOGCAT_HIGHLIGHT='(WARNING|cr_Child)'out/Default/bin/chrome_public_apk logcat# Highlights messages/tags containing WARNING and cr_Child strings.
Note: bothMessage andTag portion of logcat are matched against the pattern.
To debug C++ code, use one of the following commands:
out/Default/bin/content_shell_apk gdbout/Default/bin/chrome_public_apk gdb
SeeAndroid Debugging Instructions for more on debugging, including how to debug Java code.
For information on running tests, seeAndroid Test Instructions
Args that affect build speed:
use_remoteexec = true
(default=false)symbol_level = 0
(default=1)blink_symbol_level = 0
,v8_symbol_level = 0
is_component_build = false
(default=is_debug
)is_component_build=false
for faster .apk installs.is_java_debug = true
(default=is_debug
)treat_warnings_as_errors = false
(default=true
)android_static_analysis = "build_server"
(default="on"
)"off"
if you want to turn off static analysis altogether.incremental_install = true
(default=false
)enable_chrome_android_internal = false
(Googlers only)Normally analysis build steps like Lint and Error Prone will run as normal build steps. The build will then wait for all analysis steps to complete successfully. By offloading analysis build steps to a separate build server to be run lazily at a low priority, the actual build can complete much faster.
Note: Since the build completes before the analysis checks finish, the build will not fail if an analysis check fails.
To enable this mode, add the gn args:
android_static_analysis="build_server"
Command output will show up on the terminal that ran the build, as well as inout/Debug/buildserver.log.0
.
See the status of the server at any time via:
build/android/fast_local_dev_server.py --print-status-all
Chromium's build can be sped up significantly by using a remote execution system compatible withREAPI. This allows you to benefit from remote caching and executing many build actions in parallel on a shared cluster of workers.
To use Remote Execution, follow the correspondingLinux build instructions.
Incremental Install uses reflection and sideloading to speed up the edit & deploy cycle (normally < 10 seconds). The initial launch of the apk will be a lot slower on older Android versions (pre-N) where the OS needs to pre-optimize the side-loaded files, but then be only marginally slower after the first launch.
To enable Incremental Install, add the gn args:
incremental_install=true
Some APKs (e.g. WebView) do not work withincremental install = true
and are always built as normal APKs. This behavior is controlled vianever_incremental = true
.
Running on an emulator is the same as on a device. Refer toandroid_emulator.md for setting up emulators.
These instructions are only necessary for Chrome 51 and earlier.
In the case where you want to modify the native code for an existing release of Chrome for Android (v25+) you can do the following steps. Note that in order to get your changes into the official release, you'll need to send your change for a codereview using the regular process for committing code to chromium.
To build Chromium for Android using Docker, please follow the instructions in theDocker in Linux build instructions.