blob: 88ba48c46bd815e9569c7aedb4abf398746e606e [file] [log] [blame] [view]
dpranke1a70d0c2016-12-01 02:42:291# Checking out and building Chromium for Android
2
estevenson75e9b862017-01-05 16:49:233There are instructions for other platforms linked from the
dpranke1a70d0c2016-12-01 02:42:294[get the code](get_the_code.md) page.
tfarina2c773222016-04-05 18:43:355
dpranke1a70d0c2016-12-01 02:42:296## Instructions for Google Employees
7
8Are you a Google employee? See
Eric Stevenson36459112018-07-06 20:12:389[go/building-android-chrome](https://goto.google.com/building-android-chrome)
10instead.
dpranke0ae7cad2016-11-30 07:47:5811
tfarina2c773222016-04-05 18:43:3512[TOC]
13
dpranke0ae7cad2016-11-30 07:47:5814## System requirements
tfarina2c773222016-04-05 18:43:3515
dpranke0ae7cad2016-11-30 07:47:5816* 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.
tfarina2c773222016-04-05 18:43:3520
dpranke0ae7cad2016-11-30 07:47:5821Most development is done on Ubuntu. Other distros may or may not work;
sdy93387fa2016-12-01 01:03:4422see the [Linux instructions](linux_build_instructions.md) for some suggestions.
tfarina2c773222016-04-05 18:43:3523
dpranke0ae7cad2016-11-30 07:47:5824Building the Android client on Windows or Mac is not supported and doesn't work.
tfarina2c773222016-04-05 18:43:3525
dpranke0ae7cad2016-11-30 07:47:5826## Install `depot_tools`
tfarina2c773222016-04-05 18:43:3527
sdy93387fa2016-12-01 01:03:4428Clone the `depot_tools` repository:
dpranke0ae7cad2016-11-30 07:47:5829
sdy93387fa2016-12-01 01:03:4430```shell
Andrew Grievec81af4a2017-07-26 18:02:1331git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
sdy93387fa2016-12-01 01:03:4432```
dpranke0ae7cad2016-11-30 07:47:5833
sdy93387fa2016-12-01 01:03:4434Add `depot_tools` to the end of your PATH (you will probably want to put this
35in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools`
36to `/path/to/depot_tools`:
dpranke0ae7cad2016-11-30 07:47:5837
sdy93387fa2016-12-01 01:03:4438```shell
Andrew Grievec81af4a2017-07-26 18:02:1339export PATH="$PATH:/path/to/depot_tools"
sdy93387fa2016-12-01 01:03:4440```
dpranke0ae7cad2016-11-30 07:47:5841
42## Get the code
43
sdy93387fa2016-12-01 01:03:4444Create a `chromium` directory for the checkout and change to it (you can call
dpranke0ae7cad2016-11-30 07:47:5845this whatever you like and put it wherever you like, as
46long as the full path has no spaces):
47
sdy93387fa2016-12-01 01:03:4448```shell
Andrew Grievec81af4a2017-07-26 18:02:1349mkdir ~/chromium && cd ~/chromium
50fetch --nohooks android
sdy93387fa2016-12-01 01:03:4451```
dpranke0ae7cad2016-11-30 07:47:5852
53If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:4454adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:5855
56Expect the command to take 30 minutes on even a fast connection, and many
57hours on slower ones.
58
59If you've already installed the build dependencies on the machine (from another
sdy93387fa2016-12-01 01:03:4460checkout, for example), you can omit the `--nohooks` flag and `fetch`
dpranke0ae7cad2016-11-30 07:47:5861will automatically execute `gclient runhooks` at the end.
62
sdy93387fa2016-12-01 01:03:4463When `fetch` completes, it will have created a hidden `.gclient` file and a
64directory called `src` in the working directory. The remaining instructions
65assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5866
sdy93387fa2016-12-01 01:03:4467```shell
Andrew Grievec81af4a2017-07-26 18:02:1368cd src
sdy93387fa2016-12-01 01:03:4469```
dpranke0ae7cad2016-11-30 07:47:5870
71### Converting an existing Linux checkout
tfarina2c773222016-04-05 18:43:3572
73If you have an existing Linux checkout, you can add Android support by
sdy93387fa2016-12-01 01:03:4474appending `target_os = ['android']` to your `.gclient` file (in the
75directory above `src`):
tfarina2c773222016-04-05 18:43:3576
sdy93387fa2016-12-01 01:03:4477```shell
Andrew Grievec81af4a2017-07-26 18:02:1378echo "target_os = [ 'android' ]" >> ../.gclient
sdy93387fa2016-12-01 01:03:4479```
tfarina2c773222016-04-05 18:43:3580
sdy93387fa2016-12-01 01:03:4481Then run `gclient sync` to pull the new Android dependencies:
tfarina2c773222016-04-05 18:43:3582
sdy93387fa2016-12-01 01:03:4483```shell
Andrew Grievec81af4a2017-07-26 18:02:1384gclient sync
sdy93387fa2016-12-01 01:03:4485```
tfarina2c773222016-04-05 18:43:3586
sdy93387fa2016-12-01 01:03:4487(This is the only difference between `fetch android` and `fetch chromium`.)
tfarina2c773222016-04-05 18:43:3588
dpranke0ae7cad2016-11-30 07:47:5889### Install additional build dependencies
tfarina2c773222016-04-05 18:43:3590
dpranke0ae7cad2016-11-30 07:47:5891Once you have checked out the code, run
tfarina2c773222016-04-05 18:43:3592
sdy93387fa2016-12-01 01:03:4493```shell
Andrew Grievec81af4a2017-07-26 18:02:1394build/install-build-deps-android.sh
sdy93387fa2016-12-01 01:03:4495```
tfarina2c773222016-04-05 18:43:3596
sdy93387fa2016-12-01 01:03:4497to get all of the dependencies you need to build on Linux, *plus* all of the
dpranke0ae7cad2016-11-30 07:47:5898Android-specific dependencies (you need some of the regular Linux dependencies
sdy93387fa2016-12-01 01:03:4499because an Android build includes a bunch of the Linux tools and utilities).
tfarina2c773222016-04-05 18:43:35100
dpranke0ae7cad2016-11-30 07:47:58101### Run the hooks
tfarinaba2792fa2016-04-07 15:50:42102
dpranke0ae7cad2016-11-30 07:47:58103Once you've run `install-build-deps` at least once, you can now run the
sdy93387fa2016-12-01 01:03:44104Chromium-specific hooks, which will download additional binaries and other
dpranke0ae7cad2016-11-30 07:47:58105things you might need:
tfarinaba2792fa2016-04-07 15:50:42106
sdy93387fa2016-12-01 01:03:44107```shell
Andrew Grievec81af4a2017-07-26 18:02:13108gclient runhooks
sdy93387fa2016-12-01 01:03:44109```
tfarinaba2792fa2016-04-07 15:50:42110
sdy93387fa2016-12-01 01:03:44111*Optional*: You can also [install API
112keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
113build to talk to some Google services, but this is not necessary for most
114development and testing purposes.
tfarinaba2792fa2016-04-07 15:50:42115
dpranke1a70d0c2016-12-01 02:42:29116## Setting up the build
tfarinaba2792fa2016-04-07 15:50:42117
Tom Bridgwatereef401542018-08-17 00:54:43118Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with
119a tool called [GN](https://gn.googlesource.com/gn/+/master/docs/quick_start.md)
120to generate `.ninja` files. You can create any number of *build directories*
121with different configurations. To create a build directory which builds Chrome
122for Android, run:
tfarinaba2792fa2016-04-07 15:50:42123
sdy93387fa2016-12-01 01:03:44124```shell
Andrew Grievec81af4a2017-07-26 18:02:13125gn gen --args='target_os="android"' out/Default
sdy93387fa2016-12-01 01:03:44126```
dpranke0ae7cad2016-11-30 07:47:58127
sdy93387fa2016-12-01 01:03:44128* You only have to run this once for each new build directory, Ninja will
129 update the build files as needed.
130* You can replace `Default` with another name, but
131 it should be a subdirectory of `out`.
132* For other build arguments, including release settings, see [GN build
133 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58134 The default will be a debug component build matching the current host
135 operating system and CPU.
136* For more info on GN, run `gn help` on the command line or read the
137 [quick start guide](../tools/gn/docs/quick_start.md).
138
sdy93387fa2016-12-01 01:03:44139Also be aware that some scripts (e.g. `tombstones.py`, `adb_gdb.py`)
dpranke0ae7cad2016-11-30 07:47:58140require you to set `CHROMIUM_OUTPUT_DIR=out/Default`.
141
142## Build Chromium
143
144Build Chromium with Ninja using the command:
145
sdy93387fa2016-12-01 01:03:44146```shell
Max Morozf5b31fcd2018-08-10 21:55:48147autoninja -C out/Default chrome_public_apk
sdy93387fa2016-12-01 01:03:44148```
dpranke0ae7cad2016-11-30 07:47:58149
Max Morozf5b31fcd2018-08-10 21:55:48150`autoninja` is a wrapper that automatically provides optimal values for the
151arguments passed to `ninja`.
152
153
sdy93387fa2016-12-01 01:03:44154You can get a list of all of the other build targets from GN by running `gn ls
155out/Default` from the command line. To compile one, pass the GN label to Ninja
156with no preceding "//" (so, for `//chrome/test:unit_tests` use `ninja -C
157out/Default chrome/test:unit_tests`).
158
Andrew Grieve052376a2017-09-26 01:54:11159### Multiple Chrome APK Targets
160
161The Google Play Store allows apps to send customized `.apk` files depending on
162the version of Android running on a device. Chrome uses this feature to target
1633 different versions using 3 different ninja targets:
164
1651. `chrome_public_apk` (ChromePublic.apk)
166 * `minSdkVersion=16` (Jelly Bean).
167 * Stores libchrome.so compressed within the APK.
168 * Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9).
169 * Shipped only for Android < 21, but still works fine on Android >= 21.
1702. `chrome_modern_public_apk` (ChromeModernPublic.apk)
171 * `minSdkVersion=21` (Lollipop).
172 * Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9).
173 * Stores libchrome.so uncompressed within the APK.
174 * This APK is bigger, but the installation size is smaller since there is
175 no need to extract the .so file.
1763. `monochrome_public_apk` (MonochromePublic.apk)
177 * `minSdkVersion=24` (Nougat).
178 * Contains both WebView and Chrome within the same APK.
179 * This APK is even bigger, but much smaller than SystemWebView.apk + ChromePublic.apk.
180 * Stores libchrome.so uncompressed within the APK.
181 * Does not use Crazy Linker (WebView requires system linker).
182 * But system linker supports crazy linker features now anyways.
183
184**Note**: These instructions use `chrome_public_apk`, but either of the other
185two targets can be substituted.
186
187**Note**: These targets are actually the open-source equivalents to the
188closed-source targets that get shipped to the Play Store.
189
Andrew Grieved2ec82d2018-05-22 14:28:43190**Note**: For more in-depth differences, see [android_native_libraries.md](android_native_libraries.md).
191
Mark Pearsone9042242018-02-20 23:49:33192## Updating your checkout
193
194To update an existing checkout, you can run
195
196```shell
197$ git rebase-update
198$ gclient sync
199```
200
201The first command updates the primary Chromium source repository and rebases
202any of your local branches on top of tip-of-tree (aka the Git branch
203`origin/master`). If you don't want to use this script, you can also just use
204`git pull` or other common Git commands to update the repo.
205
206The second command syncs dependencies to the appropriate versions and re-runs
207hooks as needed.
208
dpranke0ae7cad2016-11-30 07:47:58209## Installing and Running Chromium on a device
tfarinaba2792fa2016-04-07 15:50:42210
tfarinaba2792fa2016-04-07 15:50:42211### Plug in your Android device
212
213Make sure your Android device is plugged in via USB, and USB Debugging
214is enabled.
215
216To enable USB Debugging:
217
218* Navigate to Settings \> About Phone \> Build number
219* Click 'Build number' 7 times
220* Now navigate back to Settings \> Developer Options
221* Enable 'USB Debugging' and follow the prompts
222
223You may also be prompted to allow access to your PC once your device is
224plugged in.
225
226You can check if the device is connected by running:
227
228```shell
229third_party/android_tools/sdk/platform-tools/adb devices
230```
231
232Which prints a list of connected devices. If not connected, try
233unplugging and reattaching your device.
tfarinaa68eb902016-04-12 19:43:05234
Thiemo Nagele03fb6c2018-07-31 08:29:31235### Enable apps from unknown sources
236
237Allow Android to run APKs that haven't been signed through the Play Store:
238
239* Enable 'Unknown sources' under Settings \> Security
240
241In case that setting isn't present, it may be possible to configure it via
242`adb shell` instead:
243
244```shell
245third_party/android_tools/sdk/platform-tools/adb shell settings put global verifier_verify_adb_installs 0
246```
247
tfarinaa68eb902016-04-12 19:43:05248### Build the full browser
249
tfarinaa68eb902016-04-12 19:43:05250```shell
Max Morozf5b31fcd2018-08-10 21:55:48251autoninja -C out/Default chrome_public_apk
tfarinaa68eb902016-04-12 19:43:05252```
253
254And deploy it to your Android device:
255
256```shell
Andrew Grievec81af4a2017-07-26 18:02:13257out/Default/bin/chrome_public_apk install
tfarinaa68eb902016-04-12 19:43:05258```
259
260The app will appear on the device as "Chromium".
261
262### Build Content shell
263
264Wraps the content module (but not the /chrome embedder). See
xiaoyin.l1003c0b2016-12-06 02:51:17265[https://www.chromium.org/developers/content-module](https://www.chromium.org/developers/content-module)
tfarinaa68eb902016-04-12 19:43:05266for details on the content module and content shell.
267
268```shell
Max Morozf5b31fcd2018-08-10 21:55:48269autoninja -C out/Default content_shell_apk
Andrew Grievec81af4a2017-07-26 18:02:13270out/Default/bin/content_shell_apk install
tfarinaa68eb902016-04-12 19:43:05271```
272
273this will build and install an Android apk under
Yipeng Wang613ba692017-04-25 18:24:39274`out/Default/apks/ContentShell.apk`.
tfarinaa68eb902016-04-12 19:43:05275
ntfschr29a7adab2017-03-23 21:17:08276### Build WebView
tfarinaa68eb902016-04-12 19:43:05277
xiaoyin.l1003c0b2016-12-06 02:51:17278[Android WebView](https://developer.android.com/reference/android/webkit/WebView.html)
tfarinaa68eb902016-04-12 19:43:05279is a system framework component. Since Android KitKat, it is implemented using
xiaoyin.l1003c0b2016-12-06 02:51:17280Chromium code (based off the [content module](https://dev.chromium.org/developers/content-module)).
tfarinaa68eb902016-04-12 19:43:05281
ntfschr29a7adab2017-03-23 21:17:08282If you want to build the complete Android WebView framework component and test
283the effect of your chromium changes in Android apps using WebView, you should
284follow the [Android AOSP + chromium WebView
285instructions](https://www.chromium.org/developers/how-tos/build-instructions-android-webview)
tfarinaa68eb902016-04-12 19:43:05286
287### Running
288
tfarinaa68eb902016-04-12 19:43:05289For Content shell:
290
291```shell
Andrew Grievec81af4a2017-07-26 18:02:13292out/Default/bin/content_shell_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05293```
294
295For Chrome public:
296
297```shell
Andrew Grievec81af4a2017-07-26 18:02:13298out/Default/bin/chrome_public_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05299```
300
tfarinaa68eb902016-04-12 19:43:05301### Logging and debugging
302
303Logging is often the easiest way to understand code flow. In C++ you can print
Andrew Grievec81af4a2017-07-26 18:02:13304log statements using the LOG macro. In Java, refer to
305[android_logging.md](android_logging.md).
tfarinaa68eb902016-04-12 19:43:05306
Andrew Grievec81af4a2017-07-26 18:02:13307You can see these log via `adb logcat`, or:
tfarinaa68eb902016-04-12 19:43:05308
309```shell
Andrew Grievec81af4a2017-07-26 18:02:13310out/Default/bin/chrome_public_apk logcat
tfarinaa68eb902016-04-12 19:43:05311```
312
Andrew Grievec81af4a2017-07-26 18:02:13313To debug C++ code, use one of the following commands:
tfarinaa68eb902016-04-12 19:43:05314
315```shell
Andrew Grievec81af4a2017-07-26 18:02:13316out/Default/bin/content_shell_apk gdb
317out/Default/bin/chrome_public_apk gdb
tfarinaa68eb902016-04-12 19:43:05318```
319
Philip Jägenstedt17f89962017-05-18 08:25:54320See [Android Debugging Instructions](android_debugging_instructions.md)
tfarinaa68eb902016-04-12 19:43:05321for more on debugging, including how to debug Java code.
322
323### Testing
324
Philip Jägenstedt17f89962017-05-18 08:25:54325For information on running tests, see [Android Test Instructions](android_test_instructions.md).
tfarinaa68eb902016-04-12 19:43:05326
Andrew Grievec81af4a2017-07-26 18:02:13327### Faster Edit/Deploy
tfarinaa68eb902016-04-12 19:43:05328
agrieveb0861f522018-10-17 19:48:36329#### GN Args
330Args that affect build speed:
331 * `is_component_build = true` *(default=`is_debug`)*
332 * What it does: Uses multiple `.so` files instead of just one (faster links)
333 * `is_java_debug = true` *(default=`is_debug`)*
334 * What it does: Disables ProGuard (slow build step)
335 * `enable_incremental_javac = true` *(default=`false`)*
336 * What it does: Tries to compile only a subset of `.java` files within an
337 `android_library` for subsequent builds.
338 * Can cause infrequent (once a month-ish) failures due to not recompiling a
339 class that should be recompiled.
340
341#### Incremental Install
Andrew Grievec81af4a2017-07-26 18:02:13342"Incremental install" uses reflection and side-loading to speed up the edit
estevenson75e9b862017-01-05 16:49:23343& deploy cycle (normally < 10 seconds). The initial launch of the apk will be
344a little slower since updated dex files are installed manually.
tfarinaa68eb902016-04-12 19:43:05345
tfarinaa68eb902016-04-12 19:43:05346* All apk targets have \*`_incremental` targets defined (e.g.
estevenson75e9b862017-01-05 16:49:23347 `chrome_public_apk_incremental`) except for Webview and Monochrome
tfarinaa68eb902016-04-12 19:43:05348
349Here's an example:
350
351```shell
Max Morozf5b31fcd2018-08-10 21:55:48352autoninja -C out/Default chrome_public_apk_incremental
Andrew Grievec81af4a2017-07-26 18:02:13353out/Default/bin/chrome_public_apk install --incremental --verbose
tfarinaa68eb902016-04-12 19:43:05354```
355
356For gunit tests (note that run_*_incremental automatically add
Andrew Grievec81af4a2017-07-26 18:02:13357`--fast-local-dev` when calling `test_runner.py`):
tfarinaa68eb902016-04-12 19:43:05358
359```shell
Max Morozf5b31fcd2018-08-10 21:55:48360autoninja -C out/Default base_unittests_incremental
tfarinaa68eb902016-04-12 19:43:05361out/Default/bin/run_base_unittests_incremental
362```
363
364For instrumentation tests:
365
366```shell
Max Morozf5b31fcd2018-08-10 21:55:48367autoninja -C out/Default chrome_public_test_apk_incremental
tfarinaa68eb902016-04-12 19:43:05368out/Default/bin/run_chrome_public_test_apk_incremental
369```
370
371To uninstall:
372
373```shell
Andrew Grievec81af4a2017-07-26 18:02:13374out/Default/bin/chrome_public_apk uninstall
tfarinaa68eb902016-04-12 19:43:05375```
376
Andrew Grievec81af4a2017-07-26 18:02:13377To avoid typing `_incremental` when building targets, you can use the GN arg:
estevenson75e9b862017-01-05 16:49:23378
Andrew Grievec81af4a2017-07-26 18:02:13379```
380incremental_apk_by_default = true
estevenson75e9b862017-01-05 16:49:23381```
382
Andrew Grievec81af4a2017-07-26 18:02:13383This will make `chrome_public_apk` build in incremental mode.
384
Andrew Grieveae094e392018-06-15 16:10:22385## Installing and Running Chromium on an Emulator
386
387Running on an emulator is the same as on a device. Refer to
Raphael Kubo da Costafe411ff2018-06-20 08:16:50388[android_emulator.md](android_emulator.md) for setting up emulators.
Andrew Grieveae094e392018-06-15 16:10:22389
estevenson75e9b862017-01-05 16:49:23390
dpranke0ae7cad2016-11-30 07:47:58391## Tips, tricks, and troubleshooting
tfarinaa68eb902016-04-12 19:43:05392
dpranke0ae7cad2016-11-30 07:47:58393### Rebuilding libchrome.so for a particular release
tfarinaa68eb902016-04-12 19:43:05394
yfriedman9b4327b2016-05-04 16:36:24395These instructions are only necessary for Chrome 51 and earlier.
396
tfarinaa68eb902016-04-12 19:43:05397In the case where you want to modify the native code for an existing
398release of Chrome for Android (v25+) you can do the following steps.
399Note that in order to get your changes into the official release, you'll
400need to send your change for a codereview using the regular process for
401committing code to chromium.
402
4031. Open Chrome on your Android device and visit chrome://version
4042. Copy down the id listed next to "Build ID:"
4053. Go to
406 [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)
4074. Download the listed files and follow the steps in the README.