blob: da788ade294f0a4efe6042171300456fa75eba39 [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
9[go/building-chrome](https://goto.google.com/building-chrome) instead.
dpranke0ae7cad2016-11-30 07:47:5810
tfarina2c773222016-04-05 18:43:3511[TOC]
12
dpranke0ae7cad2016-11-30 07:47:5813## System requirements
tfarina2c773222016-04-05 18:43:3514
dpranke0ae7cad2016-11-30 07:47:5815* A 64-bit Intel machine running Linux with at least 8GB of RAM. More
16 than 16GB is highly recommended.
17* At least 100GB of free disk space.
18* You must have Git and Python installed already.
tfarina2c773222016-04-05 18:43:3519
dpranke0ae7cad2016-11-30 07:47:5820Most development is done on Ubuntu. Other distros may or may not work;
sdy93387fa2016-12-01 01:03:4421see the [Linux instructions](linux_build_instructions.md) for some suggestions.
tfarina2c773222016-04-05 18:43:3522
dpranke0ae7cad2016-11-30 07:47:5823Building the Android client on Windows or Mac is not supported and doesn't work.
tfarina2c773222016-04-05 18:43:3524
dpranke0ae7cad2016-11-30 07:47:5825## Install `depot_tools`
tfarina2c773222016-04-05 18:43:3526
sdy93387fa2016-12-01 01:03:4427Clone the `depot_tools` repository:
dpranke0ae7cad2016-11-30 07:47:5828
sdy93387fa2016-12-01 01:03:4429```shell
Andrew Grievec81af4a2017-07-26 18:02:1330git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
sdy93387fa2016-12-01 01:03:4431```
dpranke0ae7cad2016-11-30 07:47:5832
sdy93387fa2016-12-01 01:03:4433Add `depot_tools` to the end of your PATH (you will probably want to put this
34in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools`
35to `/path/to/depot_tools`:
dpranke0ae7cad2016-11-30 07:47:5836
sdy93387fa2016-12-01 01:03:4437```shell
Andrew Grievec81af4a2017-07-26 18:02:1338export PATH="$PATH:/path/to/depot_tools"
sdy93387fa2016-12-01 01:03:4439```
dpranke0ae7cad2016-11-30 07:47:5840
41## Get the code
42
sdy93387fa2016-12-01 01:03:4443Create a `chromium` directory for the checkout and change to it (you can call
dpranke0ae7cad2016-11-30 07:47:5844this whatever you like and put it wherever you like, as
45long as the full path has no spaces):
46
sdy93387fa2016-12-01 01:03:4447```shell
Andrew Grievec81af4a2017-07-26 18:02:1348mkdir ~/chromium && cd ~/chromium
49fetch --nohooks android
sdy93387fa2016-12-01 01:03:4450```
dpranke0ae7cad2016-11-30 07:47:5851
52If you don't want the full repo history, you can save a lot of time by
sdy93387fa2016-12-01 01:03:4453adding the `--no-history` flag to `fetch`.
dpranke0ae7cad2016-11-30 07:47:5854
55Expect the command to take 30 minutes on even a fast connection, and many
56hours on slower ones.
57
58If you've already installed the build dependencies on the machine (from another
sdy93387fa2016-12-01 01:03:4459checkout, for example), you can omit the `--nohooks` flag and `fetch`
dpranke0ae7cad2016-11-30 07:47:5860will automatically execute `gclient runhooks` at the end.
61
sdy93387fa2016-12-01 01:03:4462When `fetch` completes, it will have created a hidden `.gclient` file and a
63directory called `src` in the working directory. The remaining instructions
64assume you have switched to the `src` directory:
dpranke0ae7cad2016-11-30 07:47:5865
sdy93387fa2016-12-01 01:03:4466```shell
Andrew Grievec81af4a2017-07-26 18:02:1367cd src
sdy93387fa2016-12-01 01:03:4468```
dpranke0ae7cad2016-11-30 07:47:5869
70### Converting an existing Linux checkout
tfarina2c773222016-04-05 18:43:3571
72If you have an existing Linux checkout, you can add Android support by
sdy93387fa2016-12-01 01:03:4473appending `target_os = ['android']` to your `.gclient` file (in the
74directory above `src`):
tfarina2c773222016-04-05 18:43:3575
sdy93387fa2016-12-01 01:03:4476```shell
Andrew Grievec81af4a2017-07-26 18:02:1377echo "target_os = [ 'android' ]" >> ../.gclient
sdy93387fa2016-12-01 01:03:4478```
tfarina2c773222016-04-05 18:43:3579
sdy93387fa2016-12-01 01:03:4480Then run `gclient sync` to pull the new Android dependencies:
tfarina2c773222016-04-05 18:43:3581
sdy93387fa2016-12-01 01:03:4482```shell
Andrew Grievec81af4a2017-07-26 18:02:1383gclient sync
sdy93387fa2016-12-01 01:03:4484```
tfarina2c773222016-04-05 18:43:3585
sdy93387fa2016-12-01 01:03:4486(This is the only difference between `fetch android` and `fetch chromium`.)
tfarina2c773222016-04-05 18:43:3587
dpranke0ae7cad2016-11-30 07:47:5888### Install additional build dependencies
tfarina2c773222016-04-05 18:43:3589
dpranke0ae7cad2016-11-30 07:47:5890Once you have checked out the code, run
tfarina2c773222016-04-05 18:43:3591
sdy93387fa2016-12-01 01:03:4492```shell
Andrew Grievec81af4a2017-07-26 18:02:1393build/install-build-deps-android.sh
sdy93387fa2016-12-01 01:03:4494```
tfarina2c773222016-04-05 18:43:3595
sdy93387fa2016-12-01 01:03:4496to get all of the dependencies you need to build on Linux, *plus* all of the
dpranke0ae7cad2016-11-30 07:47:5897Android-specific dependencies (you need some of the regular Linux dependencies
sdy93387fa2016-12-01 01:03:4498because an Android build includes a bunch of the Linux tools and utilities).
tfarina2c773222016-04-05 18:43:3599
dpranke0ae7cad2016-11-30 07:47:58100### Run the hooks
tfarinaba2792fa2016-04-07 15:50:42101
dpranke0ae7cad2016-11-30 07:47:58102Once you've run `install-build-deps` at least once, you can now run the
sdy93387fa2016-12-01 01:03:44103Chromium-specific hooks, which will download additional binaries and other
dpranke0ae7cad2016-11-30 07:47:58104things you might need:
tfarinaba2792fa2016-04-07 15:50:42105
sdy93387fa2016-12-01 01:03:44106```shell
Andrew Grievec81af4a2017-07-26 18:02:13107gclient runhooks
sdy93387fa2016-12-01 01:03:44108```
tfarinaba2792fa2016-04-07 15:50:42109
sdy93387fa2016-12-01 01:03:44110*Optional*: You can also [install API
111keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your
112build to talk to some Google services, but this is not necessary for most
113development and testing purposes.
tfarinaba2792fa2016-04-07 15:50:42114
dpranke1a70d0c2016-12-01 02:42:29115## Setting up the build
tfarinaba2792fa2016-04-07 15:50:42116
sdy93387fa2016-12-01 01:03:44117Chromium uses [Ninja](https://ninja-build.org) as its main build tool along
118with a tool called [GN](../tools/gn/docs/quick_start.md) to generate `.ninja`
119files. You can create any number of *build directories* with different
120configurations. To create a build directory which builds Chrome for Android,
121run:
tfarinaba2792fa2016-04-07 15:50:42122
sdy93387fa2016-12-01 01:03:44123```shell
Andrew Grievec81af4a2017-07-26 18:02:13124gn gen --args='target_os="android"' out/Default
sdy93387fa2016-12-01 01:03:44125```
dpranke0ae7cad2016-11-30 07:47:58126
sdy93387fa2016-12-01 01:03:44127* You only have to run this once for each new build directory, Ninja will
128 update the build files as needed.
129* You can replace `Default` with another name, but
130 it should be a subdirectory of `out`.
131* For other build arguments, including release settings, see [GN build
132 configuration](https://www.chromium.org/developers/gn-build-configuration).
dpranke0ae7cad2016-11-30 07:47:58133 The default will be a debug component build matching the current host
134 operating system and CPU.
135* For more info on GN, run `gn help` on the command line or read the
136 [quick start guide](../tools/gn/docs/quick_start.md).
137
sdy93387fa2016-12-01 01:03:44138Also be aware that some scripts (e.g. `tombstones.py`, `adb_gdb.py`)
dpranke0ae7cad2016-11-30 07:47:58139require you to set `CHROMIUM_OUTPUT_DIR=out/Default`.
140
141## Build Chromium
142
143Build Chromium with Ninja using the command:
144
sdy93387fa2016-12-01 01:03:44145```shell
Andrew Grievec81af4a2017-07-26 18:02:13146ninja -C out/Default chrome_public_apk
sdy93387fa2016-12-01 01:03:44147```
dpranke0ae7cad2016-11-30 07:47:58148
sdy93387fa2016-12-01 01:03:44149You can get a list of all of the other build targets from GN by running `gn ls
150out/Default` from the command line. To compile one, pass the GN label to Ninja
151with no preceding "//" (so, for `//chrome/test:unit_tests` use `ninja -C
152out/Default chrome/test:unit_tests`).
153
Andrew Grieve052376a2017-09-26 01:54:11154### Multiple Chrome APK Targets
155
156The Google Play Store allows apps to send customized `.apk` files depending on
157the version of Android running on a device. Chrome uses this feature to target
1583 different versions using 3 different ninja targets:
159
1601. `chrome_public_apk` (ChromePublic.apk)
161 * `minSdkVersion=16` (Jelly Bean).
162 * Stores libchrome.so compressed within the APK.
163 * Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9).
164 * Shipped only for Android < 21, but still works fine on Android >= 21.
1652. `chrome_modern_public_apk` (ChromeModernPublic.apk)
166 * `minSdkVersion=21` (Lollipop).
167 * Uses [Crazy Linker](https://cs.chromium.org/chromium/src/base/android/linker/BUILD.gn?rcl=6bb29391a86f2be58c626170156cbfaa2cbc5c91&l=9).
168 * Stores libchrome.so uncompressed within the APK.
169 * This APK is bigger, but the installation size is smaller since there is
170 no need to extract the .so file.
1713. `monochrome_public_apk` (MonochromePublic.apk)
172 * `minSdkVersion=24` (Nougat).
173 * Contains both WebView and Chrome within the same APK.
174 * This APK is even bigger, but much smaller than SystemWebView.apk + ChromePublic.apk.
175 * Stores libchrome.so uncompressed within the APK.
176 * Does not use Crazy Linker (WebView requires system linker).
177 * But system linker supports crazy linker features now anyways.
178
179**Note**: These instructions use `chrome_public_apk`, but either of the other
180two targets can be substituted.
181
182**Note**: These targets are actually the open-source equivalents to the
183closed-source targets that get shipped to the Play Store.
184
Andrew Grieved2ec82d2018-05-22 14:28:43185**Note**: For more in-depth differences, see [android_native_libraries.md](android_native_libraries.md).
186
Mark Pearsone9042242018-02-20 23:49:33187## Updating your checkout
188
189To update an existing checkout, you can run
190
191```shell
192$ git rebase-update
193$ gclient sync
194```
195
196The first command updates the primary Chromium source repository and rebases
197any of your local branches on top of tip-of-tree (aka the Git branch
198`origin/master`). If you don't want to use this script, you can also just use
199`git pull` or other common Git commands to update the repo.
200
201The second command syncs dependencies to the appropriate versions and re-runs
202hooks as needed.
203
dpranke0ae7cad2016-11-30 07:47:58204## Installing and Running Chromium on a device
tfarinaba2792fa2016-04-07 15:50:42205
tfarinaba2792fa2016-04-07 15:50:42206### Plug in your Android device
207
208Make sure your Android device is plugged in via USB, and USB Debugging
209is enabled.
210
211To enable USB Debugging:
212
213* Navigate to Settings \> About Phone \> Build number
214* Click 'Build number' 7 times
215* Now navigate back to Settings \> Developer Options
216* Enable 'USB Debugging' and follow the prompts
217
218You may also be prompted to allow access to your PC once your device is
219plugged in.
220
221You can check if the device is connected by running:
222
223```shell
224third_party/android_tools/sdk/platform-tools/adb devices
225```
226
227Which prints a list of connected devices. If not connected, try
228unplugging and reattaching your device.
tfarinaa68eb902016-04-12 19:43:05229
230### Build the full browser
231
tfarinaa68eb902016-04-12 19:43:05232```shell
Yipeng Wangfd7db172017-04-25 17:27:18233ninja -C out/Default chrome_public_apk
tfarinaa68eb902016-04-12 19:43:05234```
235
236And deploy it to your Android device:
237
238```shell
Andrew Grievec81af4a2017-07-26 18:02:13239out/Default/bin/chrome_public_apk install
tfarinaa68eb902016-04-12 19:43:05240```
241
242The app will appear on the device as "Chromium".
243
244### Build Content shell
245
246Wraps the content module (but not the /chrome embedder). See
xiaoyin.l1003c0b2016-12-06 02:51:17247[https://www.chromium.org/developers/content-module](https://www.chromium.org/developers/content-module)
tfarinaa68eb902016-04-12 19:43:05248for details on the content module and content shell.
249
250```shell
Yipeng Wangfd7db172017-04-25 17:27:18251ninja -C out/Default content_shell_apk
Andrew Grievec81af4a2017-07-26 18:02:13252out/Default/bin/content_shell_apk install
tfarinaa68eb902016-04-12 19:43:05253```
254
255this will build and install an Android apk under
Yipeng Wang613ba692017-04-25 18:24:39256`out/Default/apks/ContentShell.apk`.
tfarinaa68eb902016-04-12 19:43:05257
ntfschr29a7adab2017-03-23 21:17:08258### Build WebView
tfarinaa68eb902016-04-12 19:43:05259
xiaoyin.l1003c0b2016-12-06 02:51:17260[Android WebView](https://developer.android.com/reference/android/webkit/WebView.html)
tfarinaa68eb902016-04-12 19:43:05261is a system framework component. Since Android KitKat, it is implemented using
xiaoyin.l1003c0b2016-12-06 02:51:17262Chromium code (based off the [content module](https://dev.chromium.org/developers/content-module)).
tfarinaa68eb902016-04-12 19:43:05263
ntfschr29a7adab2017-03-23 21:17:08264If you want to build the complete Android WebView framework component and test
265the effect of your chromium changes in Android apps using WebView, you should
266follow the [Android AOSP + chromium WebView
267instructions](https://www.chromium.org/developers/how-tos/build-instructions-android-webview)
tfarinaa68eb902016-04-12 19:43:05268
269### Running
270
tfarinaa68eb902016-04-12 19:43:05271For Content shell:
272
273```shell
Andrew Grievec81af4a2017-07-26 18:02:13274out/Default/bin/content_shell_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05275```
276
277For Chrome public:
278
279```shell
Andrew Grievec81af4a2017-07-26 18:02:13280out/Default/bin/chrome_public_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05281```
282
tfarinaa68eb902016-04-12 19:43:05283### Logging and debugging
284
285Logging is often the easiest way to understand code flow. In C++ you can print
Andrew Grievec81af4a2017-07-26 18:02:13286log statements using the LOG macro. In Java, refer to
287[android_logging.md](android_logging.md).
tfarinaa68eb902016-04-12 19:43:05288
Andrew Grievec81af4a2017-07-26 18:02:13289You can see these log via `adb logcat`, or:
tfarinaa68eb902016-04-12 19:43:05290
291```shell
Andrew Grievec81af4a2017-07-26 18:02:13292out/Default/bin/chrome_public_apk logcat
tfarinaa68eb902016-04-12 19:43:05293```
294
Andrew Grievec81af4a2017-07-26 18:02:13295To debug C++ code, use one of the following commands:
tfarinaa68eb902016-04-12 19:43:05296
297```shell
Andrew Grievec81af4a2017-07-26 18:02:13298out/Default/bin/content_shell_apk gdb
299out/Default/bin/chrome_public_apk gdb
tfarinaa68eb902016-04-12 19:43:05300```
301
Philip Jägenstedt17f89962017-05-18 08:25:54302See [Android Debugging Instructions](android_debugging_instructions.md)
tfarinaa68eb902016-04-12 19:43:05303for more on debugging, including how to debug Java code.
304
305### Testing
306
Philip Jägenstedt17f89962017-05-18 08:25:54307For information on running tests, see [Android Test Instructions](android_test_instructions.md).
tfarinaa68eb902016-04-12 19:43:05308
Andrew Grievec81af4a2017-07-26 18:02:13309### Faster Edit/Deploy
tfarinaa68eb902016-04-12 19:43:05310
Andrew Grievec81af4a2017-07-26 18:02:13311"Incremental install" uses reflection and side-loading to speed up the edit
estevenson75e9b862017-01-05 16:49:23312& deploy cycle (normally < 10 seconds). The initial launch of the apk will be
313a little slower since updated dex files are installed manually.
tfarinaa68eb902016-04-12 19:43:05314
315* Make sure to set` is_component_build = true `in your GN args
316* All apk targets have \*`_incremental` targets defined (e.g.
estevenson75e9b862017-01-05 16:49:23317 `chrome_public_apk_incremental`) except for Webview and Monochrome
tfarinaa68eb902016-04-12 19:43:05318
319Here's an example:
320
321```shell
322ninja -C out/Default chrome_public_apk_incremental
Andrew Grievec81af4a2017-07-26 18:02:13323out/Default/bin/chrome_public_apk install --incremental --verbose
tfarinaa68eb902016-04-12 19:43:05324```
325
326For gunit tests (note that run_*_incremental automatically add
Andrew Grievec81af4a2017-07-26 18:02:13327`--fast-local-dev` when calling `test_runner.py`):
tfarinaa68eb902016-04-12 19:43:05328
329```shell
330ninja -C out/Default base_unittests_incremental
331out/Default/bin/run_base_unittests_incremental
332```
333
334For instrumentation tests:
335
336```shell
337ninja -C out/Default chrome_public_test_apk_incremental
338out/Default/bin/run_chrome_public_test_apk_incremental
339```
340
341To uninstall:
342
343```shell
Andrew Grievec81af4a2017-07-26 18:02:13344out/Default/bin/chrome_public_apk uninstall
tfarinaa68eb902016-04-12 19:43:05345```
346
Andrew Grievec81af4a2017-07-26 18:02:13347To avoid typing `_incremental` when building targets, you can use the GN arg:
estevenson75e9b862017-01-05 16:49:23348
Andrew Grievec81af4a2017-07-26 18:02:13349```
350incremental_apk_by_default = true
estevenson75e9b862017-01-05 16:49:23351```
352
Andrew Grievec81af4a2017-07-26 18:02:13353This will make `chrome_public_apk` build in incremental mode.
354
Andrew Grieveae094e392018-06-15 16:10:22355## Installing and Running Chromium on an Emulator
356
357Running on an emulator is the same as on a device. Refer to
Raphael Kubo da Costafe411ff2018-06-20 08:16:50358[android_emulator.md](android_emulator.md) for setting up emulators.
Andrew Grieveae094e392018-06-15 16:10:22359
estevenson75e9b862017-01-05 16:49:23360
dpranke0ae7cad2016-11-30 07:47:58361## Tips, tricks, and troubleshooting
tfarinaa68eb902016-04-12 19:43:05362
dpranke0ae7cad2016-11-30 07:47:58363### Rebuilding libchrome.so for a particular release
tfarinaa68eb902016-04-12 19:43:05364
yfriedman9b4327b2016-05-04 16:36:24365These instructions are only necessary for Chrome 51 and earlier.
366
tfarinaa68eb902016-04-12 19:43:05367In the case where you want to modify the native code for an existing
368release of Chrome for Android (v25+) you can do the following steps.
369Note that in order to get your changes into the official release, you'll
370need to send your change for a codereview using the regular process for
371committing code to chromium.
372
3731. Open Chrome on your Android device and visit chrome://version
3742. Copy down the id listed next to "Build ID:"
3753. Go to
376 [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)
3774. Download the listed files and follow the steps in the README.