dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 1 | # Checking out and building Chromium for Android |
| 2 | |
estevenson | 75e9b86 | 2017-01-05 16:49:23 | [diff] [blame] | 3 | There are instructions for other platforms linked from the |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 4 | [get the code](get_the_code.md) page. |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 5 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 6 | ## Instructions for Google Employees |
| 7 | |
| 8 | Are you a Google employee? See |
Eric Stevenson | 3645911 | 2018-07-06 20:12:38 | [diff] [blame] | 9 | [go/building-android-chrome](https://goto.google.com/building-android-chrome) |
| 10 | instead. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 11 | |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 12 | [TOC] |
| 13 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 14 | ## System requirements |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 15 | |
Bruce Dawson | c266172 | 2024-06-12 19:44:29 | [diff] [blame] | 16 | * An x86-64 machine running Linux with at least 8GB of RAM. More than 16GB is |
| 17 | highly recommended. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 18 | * At least 100GB of free disk space. |
| 19 | * You must have Git and Python installed already. |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 20 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 21 | Most development is done on Ubuntu. Other distros may or may not work; |
Tom Anderson | 93e49e49 | 2019-12-23 19:55:37 | [diff] [blame] | 22 | see the [Linux instructions](linux/build_instructions.md) for some suggestions. |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 23 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 24 | Building the Android client on Windows or Mac is not supported and doesn't work. |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 25 | |
Nate Fischer | 540458a | 2019-06-12 20:45:36 | [diff] [blame] | 26 | ## Install depot\_tools |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 27 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 28 | Clone the `depot_tools` repository: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 29 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 30 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 31 | git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 32 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 33 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 34 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 35 | in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` |
| 36 | to `/path/to/depot_tools`: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 37 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 38 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 39 | export PATH="$PATH:/path/to/depot_tools" |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 40 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 41 | |
| 42 | ## Get the code |
| 43 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 44 | Create a `chromium` directory for the checkout and change to it (you can call |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 45 | this whatever you like and put it wherever you like, as |
| 46 | long as the full path has no spaces): |
| 47 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 48 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 49 | mkdir ~/chromium && cd ~/chromium |
| 50 | fetch --nohooks android |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 51 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 52 | |
| 53 | If you don't want the full repo history, you can save a lot of time by |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 54 | adding the `--no-history` flag to `fetch`. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 55 | |
| 56 | Expect the command to take 30 minutes on even a fast connection, and many |
| 57 | hours on slower ones. |
| 58 | |
| 59 | If you've already installed the build dependencies on the machine (from another |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 60 | checkout, for example), you can omit the `--nohooks` flag and `fetch` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 61 | will automatically execute `gclient runhooks` at the end. |
| 62 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 63 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 64 | directory called `src` in the working directory. The remaining instructions |
| 65 | assume you have switched to the `src` directory: |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 66 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 67 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 68 | cd src |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 69 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 70 | |
| 71 | ### Converting an existing Linux checkout |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 72 | |
| 73 | If you have an existing Linux checkout, you can add Android support by |
Victor Vianna | e6b228f | 2022-01-26 14:42:37 | [diff] [blame] | 74 | appending `target_os = ['linux', 'android']` to your `.gclient` file (in the |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 75 | directory above `src`): |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 76 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 77 | ```shell |
Prakhar | 5db34ec | 2024-01-30 19:26:48 | [diff] [blame] | 78 | echo "target_os = [ 'linux', 'android' ]" >> ../.gclient |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 79 | ``` |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 80 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 81 | Then run `gclient sync` to pull the new Android dependencies: |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 82 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 83 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 84 | gclient sync |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 85 | ``` |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 86 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 87 | (This is the only difference between `fetch android` and `fetch chromium`.) |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 88 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 89 | ### Install additional build dependencies |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 90 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 91 | Once you have checked out the code, run |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 92 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 93 | ```shell |
Alex N. Jose | 93e7401 | 2024-09-23 19:13:21 | [diff] [blame] | 94 | build/install-build-deps.sh |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 95 | ``` |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 96 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 97 | to get all of the dependencies you need to build on Linux, *plus* all of the |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 98 | Android-specific dependencies (you need some of the regular Linux dependencies |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 99 | because an Android build includes a bunch of the Linux tools and utilities). |
tfarina | 2c77322 | 2016-04-05 18:43:35 | [diff] [blame] | 100 | |
Alex N. Jose | 93e7401 | 2024-09-23 19:13:21 | [diff] [blame] | 101 | NOTE: For 32-bit builds, the `--lib32` command line switch could be used. |
| 102 | You may run into issues where `gperf` or `pkgconf` don't get installed, |
| 103 | without it. To remedy this, and potentially other missing packages, you will |
| 104 | have to install them manually using: |
| 105 | |
| 106 | ```shell |
| 107 | sudo apt-get install {missing_pkg} |
| 108 | ``` |
| 109 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 110 | ### Run the hooks |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 111 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 112 | Once you've run `install-build-deps` at least once, you can now run the |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 113 | Chromium-specific hooks, which will download additional binaries and other |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 114 | things you might need: |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 115 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 116 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 117 | gclient runhooks |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 118 | ``` |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 119 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 120 | *Optional*: You can also [install API |
| 121 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 122 | build to talk to some Google services, but this is not necessary for most |
| 123 | development and testing purposes. |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 124 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 125 | ## Setting up the build |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 126 | |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 127 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 128 | a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md) |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 129 | to generate `.ninja` files. You can create any number of *build directories* |
| 130 | with different configurations. To create a build directory which builds Chrome |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 131 | for Android, run `gn args out/Default` and edit the file to contain the |
| 132 | following arguments: |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 133 | |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 134 | ```gn |
| 135 | target_os = "android" |
| 136 | target_cpu = "arm64" # See "Figuring out target_cpu" below |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 137 | use_remoteexec = true # Enables distributed builds. See "Faster Builds". |
Henrique Nakashima | 5425bb6d | 2024-12-23 22:09:51 | [diff] [blame] | 138 | android_static_analysis = "build_server" # Does static checks in background. See "Faster Builds". |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 139 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 140 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 141 | * You only have to run this once for each new build directory, Ninja will |
| 142 | update the build files as needed. |
| 143 | * You can replace `Default` with another name, but |
| 144 | it should be a subdirectory of `out`. |
| 145 | * For other build arguments, including release settings, see [GN build |
| 146 | configuration](https://www.chromium.org/developers/gn-build-configuration). |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 147 | The default will be a debug component build. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 148 | * For more info on GN, run `gn help` on the command line or read the |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 149 | [quick start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 150 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 151 | Also be aware that some scripts (e.g. `tombstones.py`, `adb_gdb.py`) |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 152 | require you to set `CHROMIUM_OUTPUT_DIR=out/Default`. |
| 153 | |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 154 | ### Figuring out target\_cpu |
| 155 | |
| 156 | The value of |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 157 | [`target_cpu`](https://gn.googlesource.com/gn/+/main/docs/reference.md#var_target_cpu) |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 158 | determines what instruction set to use for native code. Given a device (or |
| 159 | emulator), you can determine the correct instruction set with `adb shell getprop |
| 160 | ro.product.cpu.abi`: |
| 161 | |
| 162 | | `getprop ro.product.cpu.abi` output | `target_cpu` value | |
| 163 | |-------------------------------------|--------------------| |
| 164 | | `arm64-v8a` | `arm64` | |
| 165 | | `armeabi-v7a` | `arm` | |
| 166 | | `x86` | `x86` | |
| 167 | | `x86_64` | `x64` | |
| 168 | |
| 169 | *** promo |
| 170 | `arm` and `x86` may optionally be used instead of `arm64` and `x64` for |
| 171 | non-WebView targets. This is also allowed for Monochrome, but only when not set |
Nate Fischer | 6402abdc | 2019-07-19 21:50:19 | [diff] [blame] | 172 | as the WebView provider. |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 173 | *** |
| 174 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 175 | ## Build Chromium |
| 176 | |
| 177 | Build Chromium with Ninja using the command: |
| 178 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 179 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 180 | autoninja -C out/Default chrome_public_apk |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 181 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 182 | |
Dirk Pranke | 8bd55f2 | 2018-10-24 21:22:10 | [diff] [blame] | 183 | (`autoninja` is a wrapper that automatically provides optimal values for the |
| 184 | arguments passed to `ninja`.) |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 185 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 186 | You can get a list of all of the other build targets from GN by running `gn ls |
| 187 | out/Default` from the command line. To compile one, pass the GN label to Ninja |
Dirk Pranke | 8bd55f2 | 2018-10-24 21:22:10 | [diff] [blame] | 188 | with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 189 | out/Default chrome/test:unit_tests`). |
| 190 | |
Peter Wen | be712e64 | 2019-11-14 21:36:58 | [diff] [blame] | 191 | ### Multiple Chrome Targets |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 192 | |
Andrew Grieve | 90ba57f | 2023-05-10 19:07:40 | [diff] [blame] | 193 | The Google Play Store allows apps to send customized bundles (`.aab` files) |
Peter Wen | be712e64 | 2019-11-14 21:36:58 | [diff] [blame] | 194 | depending on the version of Android running on a device. Chrome uses this |
Andrew Grieve | f6069feb | 2021-04-29 18:29:17 | [diff] [blame] | 195 | feature to package optimized versions for different OS versions. |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 196 | |
Andrew Grieve | 90ba57f | 2023-05-10 19:07:40 | [diff] [blame] | 197 | 1. `monochrome_public_bundle` (`MonochromePublic.aab`) |
John Rummell | 98777266 | 2024-11-01 20:10:34 | [diff] [blame] | 198 | * `minSdkVersion=26` (Oreo). |
Andrew Grieve | f6069feb | 2021-04-29 18:29:17 | [diff] [blame] | 199 | * Contains both Chrome and WebView (to save disk space). |
Andrew Grieve | 90ba57f | 2023-05-10 19:07:40 | [diff] [blame] | 200 | 2. `trichrome_chrome_bundle` (`TrichromeChrome.aab`) |
Andrew Grieve | f6069feb | 2021-04-29 18:29:17 | [diff] [blame] | 201 | * `minSdkVersion=29` (Android 10). |
Erik Chen | d73c50b | 2024-01-18 02:06:37 | [diff] [blame] | 202 | * Native code shared with WebView through a "Static Shared Library APK": `trichrome_library_apk` |
Andrew Grieve | f6069feb | 2021-04-29 18:29:17 | [diff] [blame] | 203 | * Corresponding WebView target: `trichrome_webview_bundle` |
Andrew Grieve | 90ba57f | 2023-05-10 19:07:40 | [diff] [blame] | 204 | 3. `chrome_public_bundle` & `chrome_public_apk` (`ChromePublic.aab`, `ChromePublic.apk`) |
John Rummell | 98777266 | 2024-11-01 20:10:34 | [diff] [blame] | 205 | * `minSdkVersion=26` (Oreo). |
Andrew Grieve | 90ba57f | 2023-05-10 19:07:40 | [diff] [blame] | 206 | * Used for local development (to avoid building WebView). |
| 207 | * WebView packaged independently (`system_webview_bundle` / `system_webview_apk`). |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 208 | |
Andrew Grieve | f6069feb | 2021-04-29 18:29:17 | [diff] [blame] | 209 | *** note |
| 210 | **Notes:** |
| 211 | * These instructions use `chrome_public_apk`, but any of the other targets can |
| 212 | be substituted. |
| 213 | * For more about bundles, see [android_dynamic feature modules.md](android_dynamic_feature_modules.md). |
| 214 | * For more about native library packaging & loading, see [android_native_libraries.md](android_native_libraries.md). |
| 215 | * There are closed-source equivalents to these targets (for Googlers), which |
| 216 | are identical but link in some extra code. |
| 217 | *** |
Andrew Grieve | d2ec82d | 2018-05-22 14:28:43 | [diff] [blame] | 218 | |
Mark Pearson | e904224 | 2018-02-20 23:49:33 | [diff] [blame] | 219 | ## Updating your checkout |
| 220 | |
| 221 | To update an existing checkout, you can run |
| 222 | |
| 223 | ```shell |
| 224 | $ git rebase-update |
| 225 | $ gclient sync |
| 226 | ``` |
| 227 | |
| 228 | The first command updates the primary Chromium source repository and rebases |
| 229 | any of your local branches on top of tip-of-tree (aka the Git branch |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 230 | `origin/main`). If you don't want to use this script, you can also just use |
Mark Pearson | e904224 | 2018-02-20 23:49:33 | [diff] [blame] | 231 | `git pull` or other common Git commands to update the repo. |
| 232 | |
| 233 | The second command syncs dependencies to the appropriate versions and re-runs |
| 234 | hooks as needed. |
| 235 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 236 | ## Installing and Running Chromium on a device |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 237 | |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 238 | ### Plug in your Android device |
| 239 | |
| 240 | Make sure your Android device is plugged in via USB, and USB Debugging |
| 241 | is enabled. |
| 242 | |
| 243 | To enable USB Debugging: |
| 244 | |
| 245 | * Navigate to Settings \> About Phone \> Build number |
| 246 | * Click 'Build number' 7 times |
| 247 | * Now navigate back to Settings \> Developer Options |
| 248 | * Enable 'USB Debugging' and follow the prompts |
| 249 | |
| 250 | You may also be prompted to allow access to your PC once your device is |
| 251 | plugged in. |
| 252 | |
| 253 | You can check if the device is connected by running: |
| 254 | |
| 255 | ```shell |
Yun Liu | f57cceaf | 2019-03-18 21:31:23 | [diff] [blame] | 256 | third_party/android_sdk/public/platform-tools/adb devices |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 257 | ``` |
| 258 | |
| 259 | Which prints a list of connected devices. If not connected, try |
| 260 | unplugging and reattaching your device. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 261 | |
Thiemo Nagel | e03fb6c | 2018-07-31 08:29:31 | [diff] [blame] | 262 | ### Enable apps from unknown sources |
| 263 | |
| 264 | Allow Android to run APKs that haven't been signed through the Play Store: |
| 265 | |
| 266 | * Enable 'Unknown sources' under Settings \> Security |
| 267 | |
| 268 | In case that setting isn't present, it may be possible to configure it via |
| 269 | `adb shell` instead: |
| 270 | |
| 271 | ```shell |
Yun Liu | f57cceaf | 2019-03-18 21:31:23 | [diff] [blame] | 272 | third_party/android_sdk/public/platform-tools/adb shell settings put global verifier_verify_adb_installs 0 |
Thiemo Nagel | e03fb6c | 2018-07-31 08:29:31 | [diff] [blame] | 273 | ``` |
| 274 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 275 | ### Build the full browser |
| 276 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 277 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 278 | autoninja -C out/Default chrome_public_apk |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 279 | ``` |
| 280 | |
| 281 | And deploy it to your Android device: |
| 282 | |
| 283 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 284 | out/Default/bin/chrome_public_apk install |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 285 | ``` |
| 286 | |
| 287 | The app will appear on the device as "Chromium". |
| 288 | |
| 289 | ### Build Content shell |
| 290 | |
| 291 | Wraps the content module (but not the /chrome embedder). See |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 292 | [https://www.chromium.org/developers/content-module](https://www.chromium.org/developers/content-module) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 293 | for details on the content module and content shell. |
| 294 | |
| 295 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 296 | autoninja -C out/Default content_shell_apk |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 297 | out/Default/bin/content_shell_apk install |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 298 | ``` |
| 299 | |
| 300 | this will build and install an Android apk under |
Yipeng Wang | 613ba69 | 2017-04-25 18:24:39 | [diff] [blame] | 301 | `out/Default/apks/ContentShell.apk`. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 302 | |
ntfschr | 29a7adab | 2017-03-23 21:17:08 | [diff] [blame] | 303 | ### Build WebView |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 304 | |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 305 | [Android WebView](https://developer.android.com/reference/android/webkit/WebView.html) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 306 | is a system framework component. Since Android KitKat, it is implemented using |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 307 | Chromium code (based off the [content module](https://dev.chromium.org/developers/content-module)). |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 308 | |
ntfschr | 29a7adab | 2017-03-23 21:17:08 | [diff] [blame] | 309 | If you want to build the complete Android WebView framework component and test |
| 310 | the effect of your chromium changes in Android apps using WebView, you should |
| 311 | follow the [Android AOSP + chromium WebView |
| 312 | instructions](https://www.chromium.org/developers/how-tos/build-instructions-android-webview) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 313 | |
| 314 | ### Running |
| 315 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 316 | For Content shell: |
| 317 | |
| 318 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 319 | out/Default/bin/content_shell_apk launch [--args='--foo --bar'] http://example.com |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 320 | ``` |
| 321 | |
| 322 | For Chrome public: |
| 323 | |
| 324 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 325 | out/Default/bin/chrome_public_apk launch [--args='--foo --bar'] http://example.com |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 326 | ``` |
| 327 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 328 | ### Logging and debugging |
| 329 | |
| 330 | Logging is often the easiest way to understand code flow. In C++ you can print |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 331 | log statements using the LOG macro. In Java, refer to |
| 332 | [android_logging.md](android_logging.md). |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 333 | |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 334 | You can see these log via `adb logcat`, or: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 335 | |
| 336 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 337 | out/Default/bin/chrome_public_apk logcat |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 338 | ``` |
| 339 | |
Tomasz Wiszkowski | 6467f1c9 | 2021-04-08 21:54:42 | [diff] [blame] | 340 | Logcat supports an additional feature of filtering and highlighting user-defined patterns. To use |
| 341 | this mechanism, define a shell variable: `CHROMIUM_LOGCAT_HIGHLIGHT` and assign your desired |
| 342 | pattern. The pattern will be used to search for any substring (ie. no need to prefix or suffix it |
| 343 | with `.*`), eg: |
| 344 | |
| 345 | ```shell |
| 346 | export CHROMIUM_LOGCAT_HIGHLIGHT='(WARNING|cr_Child)' |
박중헌 | e605cf2a | 2023-08-22 05:17:42 | [diff] [blame] | 347 | out/Default/bin/chrome_public_apk logcat |
Tomasz Wiszkowski | 6467f1c9 | 2021-04-08 21:54:42 | [diff] [blame] | 348 | # Highlights messages/tags containing WARNING and cr_Child strings. |
| 349 | ``` |
| 350 | |
| 351 | Note: both _Message_ and _Tag_ portion of logcat are matched against the pattern. |
| 352 | |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 353 | To debug C++ code, use one of the following commands: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 354 | |
| 355 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 356 | out/Default/bin/content_shell_apk gdb |
| 357 | out/Default/bin/chrome_public_apk gdb |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 358 | ``` |
| 359 | |
Philip Jägenstedt | 17f8996 | 2017-05-18 08:25:54 | [diff] [blame] | 360 | See [Android Debugging Instructions](android_debugging_instructions.md) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 361 | for more on debugging, including how to debug Java code. |
| 362 | |
| 363 | ### Testing |
| 364 | |
Ken Rockot | 35028ca | 2019-05-30 18:50:45 | [diff] [blame] | 365 | For information on running tests, see |
Andrew Grieve | b5b3bb3 | 2023-10-04 13:55:51 | [diff] [blame] | 366 | [Android Test Instructions](/docs/testing/android_test_instructions.md) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 367 | |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 368 | ## Faster Builds |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 369 | |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 370 | ### GN Args |
| 371 | |
agrieve | b0861f52 | 2018-10-17 19:48:36 | [diff] [blame] | 372 | Args that affect build speed: |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 373 | * `use_remoteexec = true` *(default=false)* |
| 374 | * What it does: Enables distributed builds via Reclient |
| 375 | * `symbol_level = 0` *(default=1)* |
| 376 | * What it does: Disables debug information in native code. |
| 377 | * Use this when doing primarily Java development. |
| 378 | * To disable symbols only in Blink / V8: `blink_symbol_level = 0`, `v8_symbol_level = 0` |
agrieve | b0861f52 | 2018-10-17 19:48:36 | [diff] [blame] | 379 | * `is_component_build = true` *(default=`is_debug`)* |
| 380 | * What it does: Uses multiple `.so` files instead of just one (faster links) |
| 381 | * `is_java_debug = true` *(default=`is_debug`)* |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 382 | * What it does: Disables R8 (whole-program Java optimizer) |
Andrew Grieve | 4978e8d | 2020-07-21 14:29:56 | [diff] [blame] | 383 | * `treat_warnings_as_errors = false` *(default=`true`)* |
| 384 | * Causes any compiler warnings or lint checks to not fail the build. |
| 385 | * Allows you to iterate without needing to satisfy static analysis checks. |
Peter Wen | 9e3ef45 | 2022-02-02 16:48:57 | [diff] [blame] | 386 | * `android_static_analysis = "build_server"` *(default=`"on"`)* |
| 387 | * Offloads static analysis steps to the build server. Explained below. |
| 388 | * Set this to `"off"` if you want to turn off static analysis altogether. |
| 389 | * `incremental_install = true` *(default=`false`)* |
| 390 | * Makes build and install quite a bit faster. Explained in a later section. |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 391 | * `enable_chrome_android_internal = false` *(Googlers only)* |
| 392 | * Disables non-public code, which exists even when building public targets. |
| 393 | * Use this is you do not need to test internal-only things. |
agrieve | b0861f52 | 2018-10-17 19:48:36 | [diff] [blame] | 394 | |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 395 | ### Asynchronous Static Analysis |
Andrew Grieve | 2f008e2 | 2024-05-07 15:21:45 | [diff] [blame] | 396 | |
| 397 | Normally analysis build steps like Lint and Error Prone will run as normal build |
| 398 | steps. The build will then wait for all analysis steps to complete successfully. |
| 399 | By offloading analysis build steps to a separate build server to be run lazily at |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 400 | a low priority, the actual build can complete much faster. |
Peter Wen | c4bf5762 | 2021-04-12 22:12:36 | [diff] [blame] | 401 | |
Peter Wen | 38be2fbc | 2023-02-09 19:04:10 | [diff] [blame] | 402 | **Note**: Since the build completes before the analysis checks finish, the build |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 403 | will not fail if an analysis check fails. |
Peter Wen | 38be2fbc | 2023-02-09 19:04:10 | [diff] [blame] | 404 | |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 405 | To enable this mode, add the gn args: |
Peter Wen | 38be2fbc | 2023-02-09 19:04:10 | [diff] [blame] | 406 | |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 407 | ```gn |
| 408 | android_static_analysis = "build_server" |
Peter Wen | 9e3ef45 | 2022-02-02 16:48:57 | [diff] [blame] | 409 | ``` |
| 410 | |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 411 | Command output will show up on the terminal that ran the build, as well as in |
| 412 | `out/Debug/buildserver.log.0`. |
| 413 | |
| 414 | See the status of the server at any time via: |
| 415 | ``` |
| 416 | build/android/fast_local_dev_server.py --print-status-all |
Victor Hugo Vianna Silva | 3d39c7f | 2022-03-21 10:15:27 | [diff] [blame] | 417 | ``` |
Peter Wen | 9e3ef45 | 2022-02-02 16:48:57 | [diff] [blame] | 418 | |
Jenna Himawan | 4913cb8 | 2025-02-05 15:42:43 | [diff] [blame] | 419 | ### Use Reclient |
| 420 | |
| 421 | *** note |
| 422 | **Warning:** If you are a Google employee, do not follow the Reclient instructions |
| 423 | in this section. Set up remote execution as described in |
| 424 | [go/building-android-chrome](https://goto.google.com/building-android-chrome) |
| 425 | instead. |
| 426 | *** |
| 427 | |
| 428 | Chromium's build can be sped up significantly by using a remote execution system |
| 429 | compatible with [REAPI](https://github.com/bazelbuild/remote-apis). This allows |
| 430 | you to benefit from remote caching and executing many build actions in parallel |
| 431 | on a shared cluster of workers. |
| 432 | |
| 433 | To use Reclient, follow the corresponding |
| 434 | [Linux build instructions](linux/build_instructions.md#use-reclient). |
| 435 | |
Andrew Grieve | f253a88 | 2024-12-13 20:02:57 | [diff] [blame] | 436 | ### Incremental Install |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 437 | [Incremental Install](/build/android/incremental_install/README.md) uses |
Andrew Grieve | c45749e5 | 2019-10-22 20:59:56 | [diff] [blame] | 438 | reflection and sideloading to speed up the edit & deploy cycle (normally < 10 |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 439 | seconds). The initial launch of the apk will be a lot slower on older Android |
| 440 | versions (pre-N) where the OS needs to pre-optimize the side-loaded files, but |
| 441 | then be only marginally slower after the first launch. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 442 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 443 | To enable Incremental Install, add the gn args: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 444 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 445 | ```gn |
| 446 | incremental_install = true |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 447 | ``` |
| 448 | |
Daniel Cheng | 243aad3 | 2022-02-26 03:33:14 | [diff] [blame] | 449 | Some APKs (e.g. WebView) do not work with `incremental install = true` and are |
| 450 | always built as normal APKs. This behavior is controlled via |
| 451 | `never_incremental = true`. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 452 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 453 | ## Installing and Running Chromium on an Emulator |
| 454 | |
| 455 | Running on an emulator is the same as on a device. Refer to |
Raphael Kubo da Costa | fe411ff | 2018-06-20 08:16:50 | [diff] [blame] | 456 | [android_emulator.md](android_emulator.md) for setting up emulators. |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 457 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 458 | ## Tips, tricks, and troubleshooting |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 459 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 460 | ### Rebuilding libchrome.so for a particular release |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 461 | |
yfriedman | 9b4327b | 2016-05-04 16:36:24 | [diff] [blame] | 462 | These instructions are only necessary for Chrome 51 and earlier. |
| 463 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 464 | In the case where you want to modify the native code for an existing |
| 465 | release of Chrome for Android (v25+) you can do the following steps. |
| 466 | Note that in order to get your changes into the official release, you'll |
| 467 | need to send your change for a codereview using the regular process for |
| 468 | committing code to chromium. |
| 469 | |
| 470 | 1. Open Chrome on your Android device and visit chrome://version |
| 471 | 2. Copy down the id listed next to "Build ID:" |
| 472 | 3. Go to |
| 473 | [http://storage.googleapis.com/chrome-browser-components/BUILD\_ID\_FROM\_STEP\_2/index.html](http://storage.googleapis.com/chrome-browser-components/BUILD_ID_FROM_STEP_2/index.html) |
| 474 | 4. Download the listed files and follow the steps in the README. |
mohamedhany01 | 5ae3480 | 2024-10-16 16:34:41 | [diff] [blame] | 475 | |
| 476 | ### Building with Docker |
| 477 | |
| 478 | To build Chromium for Android using Docker, please follow the |
| 479 | instructions in the [Docker in Linux build instructions](/docs/linux/build_instructions.md#docker). |
| 480 | |
| 481 | *** note |
| 482 | **Note:** You need install the [Android dependencies](#install-additional-build-dependencies) after setting up the [Build dependencies](/docs/linux/build_instructions.md#install-additional-build-dependencies). |
| 483 | *** |