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 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 16 | * A 64-bit Intel machine running Linux with at least 8GB of RAM. More |
| 17 | than 16GB is highly recommended. |
| 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 |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 74 | appending `target_os = ['android']` to your `.gclient` file (in the |
| 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 |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 78 | echo "target_os = [ '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 |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 94 | build/install-build-deps-android.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 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 101 | ### Run the hooks |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 102 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 103 | 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] | 104 | Chromium-specific hooks, which will download additional binaries and other |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 105 | things you might need: |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 106 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 107 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 108 | gclient runhooks |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 109 | ``` |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 110 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 111 | *Optional*: You can also [install API |
| 112 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 113 | build to talk to some Google services, but this is not necessary for most |
| 114 | development and testing purposes. |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 115 | |
dpranke | 1a70d0c | 2016-12-01 02:42:29 | [diff] [blame] | 116 | ## Setting up the build |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 117 | |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 118 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with |
| 119 | a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) |
| 120 | to generate `.ninja` files. You can create any number of *build directories* |
| 121 | with different configurations. To create a build directory which builds Chrome |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 122 | for Android, run `gn args out/Default` and edit the file to contain the |
| 123 | following arguments: |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 124 | |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 125 | ```gn |
| 126 | target_os = "android" |
| 127 | target_cpu = "arm64" # See "Figuring out target_cpu" below |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 128 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 129 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 130 | * You only have to run this once for each new build directory, Ninja will |
| 131 | update the build files as needed. |
| 132 | * You can replace `Default` with another name, but |
| 133 | it should be a subdirectory of `out`. |
| 134 | * For other build arguments, including release settings, see [GN build |
| 135 | configuration](https://www.chromium.org/developers/gn-build-configuration). |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 136 | The default will be a debug component build. |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 137 | * For more info on GN, run `gn help` on the command line or read the |
Eric Roman | 0144675 | 2019-09-03 23:45:08 | [diff] [blame] | 138 | [quick start guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md). |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 139 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 140 | Also be aware that some scripts (e.g. `tombstones.py`, `adb_gdb.py`) |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 141 | require you to set `CHROMIUM_OUTPUT_DIR=out/Default`. |
| 142 | |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 143 | ### Figuring out target\_cpu |
| 144 | |
| 145 | The value of |
| 146 | [`target_cpu`](https://gn.googlesource.com/gn/+/master/docs/reference.md#target_cpu) |
| 147 | determines what instruction set to use for native code. Given a device (or |
| 148 | emulator), you can determine the correct instruction set with `adb shell getprop |
| 149 | ro.product.cpu.abi`: |
| 150 | |
| 151 | | `getprop ro.product.cpu.abi` output | `target_cpu` value | |
| 152 | |-------------------------------------|--------------------| |
| 153 | | `arm64-v8a` | `arm64` | |
| 154 | | `armeabi-v7a` | `arm` | |
| 155 | | `x86` | `x86` | |
| 156 | | `x86_64` | `x64` | |
| 157 | |
| 158 | *** promo |
| 159 | `arm` and `x86` may optionally be used instead of `arm64` and `x64` for |
| 160 | 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] | 161 | as the WebView provider. |
Nate Fischer | ae5fd322 | 2019-01-11 07:33:18 | [diff] [blame] | 162 | *** |
| 163 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 164 | ## Build Chromium |
| 165 | |
| 166 | Build Chromium with Ninja using the command: |
| 167 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 168 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 169 | autoninja -C out/Default chrome_public_apk |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 170 | ``` |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 171 | |
Dirk Pranke | 8bd55f2 | 2018-10-24 21:22:10 | [diff] [blame] | 172 | (`autoninja` is a wrapper that automatically provides optimal values for the |
| 173 | arguments passed to `ninja`.) |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 174 | |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 175 | You can get a list of all of the other build targets from GN by running `gn ls |
| 176 | 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] | 177 | with no preceding "//" (so, for `//chrome/test:unit_tests` use `autoninja -C |
sdy | 93387fa | 2016-12-01 01:03:44 | [diff] [blame] | 178 | out/Default chrome/test:unit_tests`). |
| 179 | |
Peter Wen | be712e64 | 2019-11-14 21:36:58 | [diff] [blame] | 180 | ### Multiple Chrome Targets |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 181 | |
Peter Wen | be712e64 | 2019-11-14 21:36:58 | [diff] [blame] | 182 | The Google Play Store allows apps to send customized `.apk` or `.aab` files |
| 183 | depending on the version of Android running on a device. Chrome uses this |
| 184 | feature to target 4 different versions using 4 different ninja targets: |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 185 | |
| 186 | 1. `chrome_public_apk` (ChromePublic.apk) |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 187 | * Used for local development and tests (simpler than using bundle targets). |
| 188 | * Same configuration as chrome_modern_public_bundle. |
| 189 | 2. `chrome_modern_public_bundle` (MonochromePublic.aab) |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 190 | * `minSdkVersion=21` (Lollipop). |
| 191 | * Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9). |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 192 | * Stores native library with "crazy." prefix to prevent extraction. |
| 193 | 3. `monochrome_public_bundle` (MonochromePublic.aab) |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 194 | * `minSdkVersion=24` (Nougat). |
| 195 | * Contains both WebView and Chrome within the same APK. |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 196 | * This bundle is larger than ChromeModern, but much smaller than SUM(SystemWebView, ChromeModern) |
Torne (Richard Coles) | d8bc292 | 2019-05-01 21:26:52 | [diff] [blame] | 197 | * Does not use Crazy Linker (WebView requires system linker). |
| 198 | * But system linker supports crazy linker features now anyways. |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 199 | 4. `trichrome_chrome_bundle` and `trichrome_library_apk` (TrichromeChrome.aab and TrichromeLibrary.apk) |
Torne (Richard Coles) | d8bc292 | 2019-05-01 21:26:52 | [diff] [blame] | 200 | * `minSdkVersion=Q` (Q). |
| 201 | * TrichromeChrome contains only the Chrome code that is not shared with WebView. |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 202 | * TrichromeLibrary contains the shared code and is a "static shared library APK". |
Torne (Richard Coles) | d8bc292 | 2019-05-01 21:26:52 | [diff] [blame] | 203 | * Stores libmonochrome.so uncompressed within TrichromeLibrary.apk. |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 204 | * Uses `android_dlopen_ext` to load native libraries with shared RELRO's |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 205 | |
Andrew Grieve | 84bf1dd | 2020-07-06 20:31:50 | [diff] [blame] | 206 | **Note**: These instructions use `chrome_public_apk`, but any of the other |
| 207 | targets can be substituted. |
Andrew Grieve | 052376a | 2017-09-26 01:54:11 | [diff] [blame] | 208 | |
| 209 | **Note**: These targets are actually the open-source equivalents to the |
| 210 | closed-source targets that get shipped to the Play Store. |
| 211 | |
Andrew Grieve | d2ec82d | 2018-05-22 14:28:43 | [diff] [blame] | 212 | **Note**: For more in-depth differences, see [android_native_libraries.md](android_native_libraries.md). |
| 213 | |
Mark Pearson | e904224 | 2018-02-20 23:49:33 | [diff] [blame] | 214 | ## Updating your checkout |
| 215 | |
| 216 | To update an existing checkout, you can run |
| 217 | |
| 218 | ```shell |
| 219 | $ git rebase-update |
| 220 | $ gclient sync |
| 221 | ``` |
| 222 | |
| 223 | The first command updates the primary Chromium source repository and rebases |
| 224 | any of your local branches on top of tip-of-tree (aka the Git branch |
| 225 | `origin/master`). If you don't want to use this script, you can also just use |
| 226 | `git pull` or other common Git commands to update the repo. |
| 227 | |
| 228 | The second command syncs dependencies to the appropriate versions and re-runs |
| 229 | hooks as needed. |
| 230 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 231 | ## Installing and Running Chromium on a device |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 232 | |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 233 | ### Plug in your Android device |
| 234 | |
| 235 | Make sure your Android device is plugged in via USB, and USB Debugging |
| 236 | is enabled. |
| 237 | |
| 238 | To enable USB Debugging: |
| 239 | |
| 240 | * Navigate to Settings \> About Phone \> Build number |
| 241 | * Click 'Build number' 7 times |
| 242 | * Now navigate back to Settings \> Developer Options |
| 243 | * Enable 'USB Debugging' and follow the prompts |
| 244 | |
| 245 | You may also be prompted to allow access to your PC once your device is |
| 246 | plugged in. |
| 247 | |
| 248 | You can check if the device is connected by running: |
| 249 | |
| 250 | ```shell |
Yun Liu | f57cceaf | 2019-03-18 21:31:23 | [diff] [blame] | 251 | third_party/android_sdk/public/platform-tools/adb devices |
tfarina | ba2792fa | 2016-04-07 15:50:42 | [diff] [blame] | 252 | ``` |
| 253 | |
| 254 | Which prints a list of connected devices. If not connected, try |
| 255 | unplugging and reattaching your device. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 256 | |
Thiemo Nagel | e03fb6c | 2018-07-31 08:29:31 | [diff] [blame] | 257 | ### Enable apps from unknown sources |
| 258 | |
| 259 | Allow Android to run APKs that haven't been signed through the Play Store: |
| 260 | |
| 261 | * Enable 'Unknown sources' under Settings \> Security |
| 262 | |
| 263 | In case that setting isn't present, it may be possible to configure it via |
| 264 | `adb shell` instead: |
| 265 | |
| 266 | ```shell |
Yun Liu | f57cceaf | 2019-03-18 21:31:23 | [diff] [blame] | 267 | 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] | 268 | ``` |
| 269 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 270 | ### Build the full browser |
| 271 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 272 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 273 | autoninja -C out/Default chrome_public_apk |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 274 | ``` |
| 275 | |
| 276 | And deploy it to your Android device: |
| 277 | |
| 278 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 279 | out/Default/bin/chrome_public_apk install |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 280 | ``` |
| 281 | |
| 282 | The app will appear on the device as "Chromium". |
| 283 | |
| 284 | ### Build Content shell |
| 285 | |
| 286 | Wraps the content module (but not the /chrome embedder). See |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 287 | [https://www.chromium.org/developers/content-module](https://www.chromium.org/developers/content-module) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 288 | for details on the content module and content shell. |
| 289 | |
| 290 | ```shell |
Max Moroz | f5b31fcd | 2018-08-10 21:55:48 | [diff] [blame] | 291 | autoninja -C out/Default content_shell_apk |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 292 | out/Default/bin/content_shell_apk install |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 293 | ``` |
| 294 | |
| 295 | this will build and install an Android apk under |
Yipeng Wang | 613ba69 | 2017-04-25 18:24:39 | [diff] [blame] | 296 | `out/Default/apks/ContentShell.apk`. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 297 | |
ntfschr | 29a7adab | 2017-03-23 21:17:08 | [diff] [blame] | 298 | ### Build WebView |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 299 | |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 300 | [Android WebView](https://developer.android.com/reference/android/webkit/WebView.html) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 301 | is a system framework component. Since Android KitKat, it is implemented using |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 302 | Chromium code (based off the [content module](https://dev.chromium.org/developers/content-module)). |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 303 | |
ntfschr | 29a7adab | 2017-03-23 21:17:08 | [diff] [blame] | 304 | If you want to build the complete Android WebView framework component and test |
| 305 | the effect of your chromium changes in Android apps using WebView, you should |
| 306 | follow the [Android AOSP + chromium WebView |
| 307 | instructions](https://www.chromium.org/developers/how-tos/build-instructions-android-webview) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 308 | |
| 309 | ### Running |
| 310 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 311 | For Content shell: |
| 312 | |
| 313 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 314 | out/Default/bin/content_shell_apk launch [--args='--foo --bar'] http://example.com |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 315 | ``` |
| 316 | |
| 317 | For Chrome public: |
| 318 | |
| 319 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 320 | out/Default/bin/chrome_public_apk launch [--args='--foo --bar'] http://example.com |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 321 | ``` |
| 322 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 323 | ### Logging and debugging |
| 324 | |
| 325 | 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] | 326 | log statements using the LOG macro. In Java, refer to |
| 327 | [android_logging.md](android_logging.md). |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 328 | |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 329 | You can see these log via `adb logcat`, or: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 330 | |
| 331 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 332 | out/Default/bin/chrome_public_apk logcat |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 333 | ``` |
| 334 | |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 335 | To debug C++ code, use one of the following commands: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 336 | |
| 337 | ```shell |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 338 | out/Default/bin/content_shell_apk gdb |
| 339 | out/Default/bin/chrome_public_apk gdb |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 340 | ``` |
| 341 | |
Philip Jägenstedt | 17f8996 | 2017-05-18 08:25:54 | [diff] [blame] | 342 | See [Android Debugging Instructions](android_debugging_instructions.md) |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 343 | for more on debugging, including how to debug Java code. |
| 344 | |
| 345 | ### Testing |
| 346 | |
Ken Rockot | 35028ca | 2019-05-30 18:50:45 | [diff] [blame] | 347 | For information on running tests, see |
| 348 | [Android Test Instructions](testing/android_test_instructions.md). |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 349 | |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 350 | ### Faster Edit/Deploy |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 351 | |
agrieve | b0861f52 | 2018-10-17 19:48:36 | [diff] [blame] | 352 | #### GN Args |
| 353 | Args that affect build speed: |
| 354 | * `is_component_build = true` *(default=`is_debug`)* |
| 355 | * What it does: Uses multiple `.so` files instead of just one (faster links) |
| 356 | * `is_java_debug = true` *(default=`is_debug`)* |
| 357 | * What it does: Disables ProGuard (slow build step) |
Andrew Grieve | 4978e8d | 2020-07-21 14:29:56 | [diff] [blame] | 358 | * `treat_warnings_as_errors = false` *(default=`true`)* |
| 359 | * Causes any compiler warnings or lint checks to not fail the build. |
| 360 | * Allows you to iterate without needing to satisfy static analysis checks. |
Peter Wen | ca2ff53 | 2020-07-22 15:35:22 | [diff] [blame] | 361 | * `use_errorprone_java_compiler = false` *(default=`true`)* |
Andrew Grieve | 4978e8d | 2020-07-21 14:29:56 | [diff] [blame] | 362 | * Don't run Errorprone checks when compiling Java files. |
| 363 | * Speeds up Java compiles by ~30% at the cost of not seeing ErrorProne |
| 364 | warnings. |
| 365 | * `disable_android_lint = true` *(default=`false`)* |
| 366 | * Don't run Android Lint when building APK / App Bundle targets. |
| 367 | * Lint usually takes > 60 seconds to run, so disabling it dramatically |
| 368 | reduces incremental build times. |
agrieve | b0861f52 | 2018-10-17 19:48:36 | [diff] [blame] | 369 | |
| 370 | #### Incremental Install |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 371 | [Incremental Install](/build/android/incremental_install/README.md) uses |
Andrew Grieve | c45749e5 | 2019-10-22 20:59:56 | [diff] [blame] | 372 | reflection and sideloading to speed up the edit & deploy cycle (normally < 10 |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 373 | seconds). The initial launch of the apk will be a lot slower on older Android |
| 374 | versions (pre-N) where the OS needs to pre-optimize the side-loaded files, but |
| 375 | then be only marginally slower after the first launch. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 376 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 377 | To enable Incremental Install, add the gn args: |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 378 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 379 | ```gn |
| 380 | incremental_install = true |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 381 | ``` |
| 382 | |
Andrew Grieve | e1dc23f | 2019-10-22 16:26:36 | [diff] [blame] | 383 | Some APKs (e.g. WebView) do not work with incremental install, and are |
Andrew Grieve | c45749e5 | 2019-10-22 20:59:56 | [diff] [blame] | 384 | blacklisted from being built as such (via `never_incremental = true`), so are |
| 385 | build as normal APKs even when `incremental_install = true`. |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 386 | |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 387 | ## Installing and Running Chromium on an Emulator |
| 388 | |
| 389 | 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] | 390 | [android_emulator.md](android_emulator.md) for setting up emulators. |
Andrew Grieve | ae094e39 | 2018-06-15 16:10:22 | [diff] [blame] | 391 | |
estevenson | 75e9b86 | 2017-01-05 16:49:23 | [diff] [blame] | 392 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 393 | ## Tips, tricks, and troubleshooting |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 394 | |
dpranke | 0ae7cad | 2016-11-30 07:47:58 | [diff] [blame] | 395 | ### Rebuilding libchrome.so for a particular release |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 396 | |
yfriedman | 9b4327b | 2016-05-04 16:36:24 | [diff] [blame] | 397 | These instructions are only necessary for Chrome 51 and earlier. |
| 398 | |
tfarina | a68eb90 | 2016-04-12 19:43:05 | [diff] [blame] | 399 | In the case where you want to modify the native code for an existing |
| 400 | release of Chrome for Android (v25+) you can do the following steps. |
| 401 | Note that in order to get your changes into the official release, you'll |
| 402 | need to send your change for a codereview using the regular process for |
| 403 | committing code to chromium. |
| 404 | |
| 405 | 1. Open Chrome on your Android device and visit chrome://version |
| 406 | 2. Copy down the id listed next to "Build ID:" |
| 407 | 3. Go to |
| 408 | [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) |
| 409 | 4. Download the listed files and follow the steps in the README. |