blob: 17003805b20c9ab9f402d0deaa393e3a0ddff89f [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
dpranke0ae7cad2016-11-30 07:47:58154## Installing and Running Chromium on a device
tfarinaba2792fa2016-04-07 15:50:42155
tfarinaba2792fa2016-04-07 15:50:42156Prepare the environment:
157
158```shell
Andrew Grievec81af4a2017-07-26 18:02:13159. build/android/envsetup.sh
tfarinaba2792fa2016-04-07 15:50:42160```
161
162### Plug in your Android device
163
164Make sure your Android device is plugged in via USB, and USB Debugging
165is enabled.
166
167To enable USB Debugging:
168
169* Navigate to Settings \> About Phone \> Build number
170* Click 'Build number' 7 times
171* Now navigate back to Settings \> Developer Options
172* Enable 'USB Debugging' and follow the prompts
173
174You may also be prompted to allow access to your PC once your device is
175plugged in.
176
177You can check if the device is connected by running:
178
179```shell
180third_party/android_tools/sdk/platform-tools/adb devices
181```
182
183Which prints a list of connected devices. If not connected, try
184unplugging and reattaching your device.
tfarinaa68eb902016-04-12 19:43:05185
186### Build the full browser
187
tfarinaa68eb902016-04-12 19:43:05188```shell
Yipeng Wangfd7db172017-04-25 17:27:18189ninja -C out/Default chrome_public_apk
tfarinaa68eb902016-04-12 19:43:05190```
191
192And deploy it to your Android device:
193
194```shell
Andrew Grievec81af4a2017-07-26 18:02:13195out/Default/bin/chrome_public_apk install
tfarinaa68eb902016-04-12 19:43:05196```
197
198The app will appear on the device as "Chromium".
199
200### Build Content shell
201
202Wraps the content module (but not the /chrome embedder). See
xiaoyin.l1003c0b2016-12-06 02:51:17203[https://www.chromium.org/developers/content-module](https://www.chromium.org/developers/content-module)
tfarinaa68eb902016-04-12 19:43:05204for details on the content module and content shell.
205
206```shell
Yipeng Wangfd7db172017-04-25 17:27:18207ninja -C out/Default content_shell_apk
Andrew Grievec81af4a2017-07-26 18:02:13208out/Default/bin/content_shell_apk install
tfarinaa68eb902016-04-12 19:43:05209```
210
211this will build and install an Android apk under
Yipeng Wang613ba692017-04-25 18:24:39212`out/Default/apks/ContentShell.apk`.
tfarinaa68eb902016-04-12 19:43:05213
ntfschr29a7adab2017-03-23 21:17:08214### Build WebView
tfarinaa68eb902016-04-12 19:43:05215
xiaoyin.l1003c0b2016-12-06 02:51:17216[Android WebView](https://developer.android.com/reference/android/webkit/WebView.html)
tfarinaa68eb902016-04-12 19:43:05217is a system framework component. Since Android KitKat, it is implemented using
xiaoyin.l1003c0b2016-12-06 02:51:17218Chromium code (based off the [content module](https://dev.chromium.org/developers/content-module)).
tfarinaa68eb902016-04-12 19:43:05219
ntfschr29a7adab2017-03-23 21:17:08220If you want to build the complete Android WebView framework component and test
221the effect of your chromium changes in Android apps using WebView, you should
222follow the [Android AOSP + chromium WebView
223instructions](https://www.chromium.org/developers/how-tos/build-instructions-android-webview)
tfarinaa68eb902016-04-12 19:43:05224
225### Running
226
tfarinaa68eb902016-04-12 19:43:05227For Content shell:
228
229```shell
Andrew Grievec81af4a2017-07-26 18:02:13230out/Default/bin/content_shell_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05231```
232
233For Chrome public:
234
235```shell
Andrew Grievec81af4a2017-07-26 18:02:13236out/Default/bin/chrome_public_apk launch [--args='--foo --bar'] http://example.com
tfarinaa68eb902016-04-12 19:43:05237```
238
tfarinaa68eb902016-04-12 19:43:05239### Logging and debugging
240
241Logging is often the easiest way to understand code flow. In C++ you can print
Andrew Grievec81af4a2017-07-26 18:02:13242log statements using the LOG macro. In Java, refer to
243[android_logging.md](android_logging.md).
tfarinaa68eb902016-04-12 19:43:05244
Andrew Grievec81af4a2017-07-26 18:02:13245You can see these log via `adb logcat`, or:
tfarinaa68eb902016-04-12 19:43:05246
247```shell
Andrew Grievec81af4a2017-07-26 18:02:13248out/Default/bin/chrome_public_apk logcat
tfarinaa68eb902016-04-12 19:43:05249```
250
Andrew Grievec81af4a2017-07-26 18:02:13251To debug C++ code, use one of the following commands:
tfarinaa68eb902016-04-12 19:43:05252
253```shell
Andrew Grievec81af4a2017-07-26 18:02:13254out/Default/bin/content_shell_apk gdb
255out/Default/bin/chrome_public_apk gdb
tfarinaa68eb902016-04-12 19:43:05256```
257
Philip Jägenstedt17f89962017-05-18 08:25:54258See [Android Debugging Instructions](android_debugging_instructions.md)
tfarinaa68eb902016-04-12 19:43:05259for more on debugging, including how to debug Java code.
260
261### Testing
262
Philip Jägenstedt17f89962017-05-18 08:25:54263For information on running tests, see [Android Test Instructions](android_test_instructions.md).
tfarinaa68eb902016-04-12 19:43:05264
Andrew Grievec81af4a2017-07-26 18:02:13265### Faster Edit/Deploy
tfarinaa68eb902016-04-12 19:43:05266
Andrew Grievec81af4a2017-07-26 18:02:13267"Incremental install" uses reflection and side-loading to speed up the edit
estevenson75e9b862017-01-05 16:49:23268& deploy cycle (normally < 10 seconds). The initial launch of the apk will be
269a little slower since updated dex files are installed manually.
tfarinaa68eb902016-04-12 19:43:05270
271* Make sure to set` is_component_build = true `in your GN args
272* All apk targets have \*`_incremental` targets defined (e.g.
estevenson75e9b862017-01-05 16:49:23273 `chrome_public_apk_incremental`) except for Webview and Monochrome
tfarinaa68eb902016-04-12 19:43:05274
275Here's an example:
276
277```shell
278ninja -C out/Default chrome_public_apk_incremental
Andrew Grievec81af4a2017-07-26 18:02:13279out/Default/bin/chrome_public_apk install --incremental --verbose
tfarinaa68eb902016-04-12 19:43:05280```
281
282For gunit tests (note that run_*_incremental automatically add
Andrew Grievec81af4a2017-07-26 18:02:13283`--fast-local-dev` when calling `test_runner.py`):
tfarinaa68eb902016-04-12 19:43:05284
285```shell
286ninja -C out/Default base_unittests_incremental
287out/Default/bin/run_base_unittests_incremental
288```
289
290For instrumentation tests:
291
292```shell
293ninja -C out/Default chrome_public_test_apk_incremental
294out/Default/bin/run_chrome_public_test_apk_incremental
295```
296
297To uninstall:
298
299```shell
Andrew Grievec81af4a2017-07-26 18:02:13300out/Default/bin/chrome_public_apk uninstall
tfarinaa68eb902016-04-12 19:43:05301```
302
Andrew Grievec81af4a2017-07-26 18:02:13303To avoid typing `_incremental` when building targets, you can use the GN arg:
estevenson75e9b862017-01-05 16:49:23304
Andrew Grievec81af4a2017-07-26 18:02:13305```
306incremental_apk_by_default = true
estevenson75e9b862017-01-05 16:49:23307```
308
Andrew Grievec81af4a2017-07-26 18:02:13309This will make `chrome_public_apk` build in incremental mode.
310
estevenson75e9b862017-01-05 16:49:23311
dpranke0ae7cad2016-11-30 07:47:58312## Tips, tricks, and troubleshooting
tfarinaa68eb902016-04-12 19:43:05313
dpranke0ae7cad2016-11-30 07:47:58314### Rebuilding libchrome.so for a particular release
tfarinaa68eb902016-04-12 19:43:05315
yfriedman9b4327b2016-05-04 16:36:24316These instructions are only necessary for Chrome 51 and earlier.
317
tfarinaa68eb902016-04-12 19:43:05318In the case where you want to modify the native code for an existing
319release of Chrome for Android (v25+) you can do the following steps.
320Note that in order to get your changes into the official release, you'll
321need to send your change for a codereview using the regular process for
322committing code to chromium.
323
3241. Open Chrome on your Android device and visit chrome://version
3252. Copy down the id listed next to "Build ID:"
3263. Go to
327 [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)
3284. Download the listed files and follow the steps in the README.