blob: 8340291cd6337a61d7b904d0e53f7243516f1068 [file] [log] [blame] [view]
tfarina2c773222016-04-05 18:43:351# Android Build Instructions
2
3[TOC]
4
5## Prerequisites
6
7A Linux build machine capable of building [Chrome for
8Linux](https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions_prerequisites.md).
9Other (Mac/Windows) platforms are not supported for Android.
10
11## Getting the code
12
13First, check out and install the [depot\_tools
14package](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up).
15
16Then, if you have no existing checkout, create your source directory and
17get the code:
18
19```shell
20mkdir ~/chromium && cd ~/chromium
21fetch --nohooks android # This will take 30 minutes on a fast connection
22```
23
24If you have an existing Linux checkout, you can add Android support by
25appending `target_os = ['android']` to your .gclient file (in the
26directory above src):
27
28```shell
29cat > .gclient <<EOF
30 solutions = [ ...existing stuff in here... ]
31 target_os = [ 'android' ] # Add this to get Android stuff checked out.
32EOF
33```
34
35Then run gclient sync to get the Android stuff checked out:
36
37```shell
38gclient sync
39```
40
41## (Optional) Check out LKGR
42
43If you want a single build of Chromium in a known good state, sync to
44the LKGR ("last known good revision"). You can find it
45[here](http://chromium-status.appspot.com/lkgr), and the last 100
46[here](http://chromium-status.appspot.com/revisions). Run:
47
48```shell
49gclient sync --nohooks -r <lkgr-sha1>
50```
51
52This is not needed for a typical developer workflow; only for one-time
53builds of Chromium.
54
55## Configure your build
56
57Android builds can be run with GN or GYP, though GN incremental builds
58are the fastest option and GN will soon be the only supported option.
59They are both meta-build systems that generate nina files for the
60Android build. Both builds are regularly tested on the build waterfall.
61
62### Configure GYP (deprecated -- use GN instead)
63
64If you are using GYP, next to the .gclient file, create a a file called
65'chromium.gyp_env' with the following contents:
66
67```shell
68echo "{ 'GYP_DEFINES': 'OS=android target_arch=arm', }" > chromium.gyp_env
69```
70
71Note that "arm" is the default architecture and can be omitted. If
72building for x86 or MIPS devices, change `target_arch` to "ia32" or
73"mipsel".
74
75 **NOTE:** If you are using the `GYP_DEFINES` environment variable, it
76will override any settings in this file. Either clear it or set it to
77the values above before running `gclient runhooks`.
tfarinaba2792fa2016-04-07 15:50:4278
79 See
80[build/android/developer\_recommended\_flags.gypi](https://code.google.com/p/chromium/codesearch#chromium/src/build/android/developer_recommended_flags.gypi&sq=package:chromium&type=cs&q=file:android/developer_recommended_flags.gypi&l=1)
81for other recommended GYP settings.
82 Once chromium.gyp_env is ready, you need to run the following command
83to update projects from gyp files. You may need to run this again when
84you have added new files, updated gyp files, or sync'ed your
85repository.
86
87```shell
88gclient runhooks
89```
90
91#### This will download more things and prompt you to accept Terms of Service for Android SDK packages.
92
93## Configure GN (recommended)
94
95If you are using GN, create a build directory and set the build flags
96with:
97
98```shell
99gn args out/Default
100```
101
102 You can replace out/Default with another name you choose inside the out
103directory. Do not use GYP's out/Debug or out/Release directories, as
104they may conflict with GYP builds.
105
106Also be aware that some scripts (e.g. tombstones.py, adb_gdb.py)
107require you to set `CHROMIUM_OUTPUT_DIR=out/Default`.
108
109This command will bring up your editor with the GN build args. In this
110file add:
111
112```
113target_os = "android"
114target_cpu = "arm" # (default)
115is_debug = true # (default)
116
117# Other args you may want to set:
118is_component_build = true
119is_clang = true
120symbol_level = 1 # Faster build with fewer symbols. -g1 rather than -g2
121enable_incremental_javac = true # Much faster; experimental
122symbol_level = 1 # Faster build with fewer symbols. -g1 rather than -g2
123enable_incremental_javac = true # Much faster; experimental
124```
125
126You can also specify `target_cpu` values of "x86" and "mipsel". Re-run
127gn args on that directory to edit the flags in the future. See the [GN
128build
129configuration](https://www.chromium.org/developers/gn-build-configuration)
130page for other flags you may want to set.
131
132### Install build dependencies
133
134Update the system packages required to build by running:
135
136```shell
137./build/install-build-deps-android.sh
138```
139
140Make also sure that OpenJDK 1.7 is selected as default:
141
142`sudo update-alternatives --config javac`
143`sudo update-alternatives --config java`
144`sudo update-alternatives --config javaws`
145`sudo update-alternatives --config javap`
146`sudo update-alternatives --config jar`
147`sudo update-alternatives --config jarsigner`
148
149### Synchronize sub-directories.
150
151```shell
152gclient sync
153```
154
155## Build and install the APKs
156
157If the `adb_install_apk.py` script below fails, make sure aapt is in
158your PATH. If not, add aapt's path to your PATH environment variable (it
159should be
160`/path/to/src/third_party/android_tools/sdk/build-tools/{latest_version}/`).
161
162Prepare the environment:
163
164```shell
165. build/android/envsetup.sh
166```
167
168### Plug in your Android device
169
170Make sure your Android device is plugged in via USB, and USB Debugging
171is enabled.
172
173To enable USB Debugging:
174
175* Navigate to Settings \> About Phone \> Build number
176* Click 'Build number' 7 times
177* Now navigate back to Settings \> Developer Options
178* Enable 'USB Debugging' and follow the prompts
179
180You may also be prompted to allow access to your PC once your device is
181plugged in.
182
183You can check if the device is connected by running:
184
185```shell
186third_party/android_tools/sdk/platform-tools/adb devices
187```
188
189Which prints a list of connected devices. If not connected, try
190unplugging and reattaching your device.
tfarinaa68eb902016-04-12 19:43:05191
192### Build the full browser
193
194**Note: When adding new resource files or java files in gyp builds, you
195need to run 'gclient runhooks' again to get them in the build.**
196
197```shell
198ninja -C out/Release chrome_public_apk
199```
200
201And deploy it to your Android device:
202
203```shell
204build/android/adb_install_apk.py out/Release/apks/ChromePublic.apk # For gyp.
205CHROMIUM_OUTPUT_DIR=$gndir build/android/adb_install_apk.py $gndir/apks/ChromePublic.apk # for gn.
206```
207
208The app will appear on the device as "Chromium".
209
210### Build Content shell
211
212Wraps the content module (but not the /chrome embedder). See
213[http://www.chromium.org/developers/content-module](http://www.chromium.org/developers/content-module)
214for details on the content module and content shell.
215
216```shell
217ninja -C out/Release content_shell_apk
218build/android/adb_install_apk.py out/Release/apks/ContentShell.apk
219```
220
221this will build and install an Android apk under
222`out/Release/apks/ContentShell.apk`. For GYP, replace `Release` with `Debug`
223above if you want to generate a Debug app. If you are using GN, substitute the
224name you initially gave to your build directory.
225
226If you use custom out dir instead of standard out/ dir, use
227CHROMIUM_OUT_DIR env.
228
229```shell
230export CHROMIUM_OUT_DIR=out_android
231```
232
233### Build WebView shell
234
235[Android WebView](http://developer.android.com/reference/android/webkit/WebView.html)
236is a system framework component. Since Android KitKat, it is implemented using
237Chromium code (based off the [content module](http://dev.chromium.org/developers/content-module)).
238It is possible to test modifications to WebView using a simple test shell. The
239WebView shell is a view with a URL bar at the top (see [code](https://code.google.com/p/chromium/codesearch#chromium/src/android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java))
240and is **independent** of the WebView **implementation in the Android system** (
241the WebView shell is essentially a standalone unbundled app).
242As drawback, the shell runs in non-production rendering mode only.
243
244```shell
245ninja -C out/Release android_webview_apk
246build/android/adb_install_apk.py out/Release/apks/AndroidWebView.apk
247```
248
249If, instead, you want to build the complete Android WebView framework component and test the effect of your chromium changes in other Android app using the WebView, you should follow the [Android AOSP + chromium WebView instructions](http://www.chromium.org/developers/how-tos/build-instructions-android-webview)
250
251### Running
252
253Set [command line flags](https://www.chromium.org/developers/how-tos/run-chromium-with-flags) if necessary.
254
255For Content shell:
256
257```shell
258build/android/adb_run_content_shell http://example.com
259```
260
261For Chrome public:
262
263```shell
264build/android/adb_run_chrome_public http://example.com
265```
266
267For Android WebView shell:
268
269```shell
270build/android/adb_run_android_webview_shell http://example.com
271```
272
273### Logging and debugging
274
275Logging is often the easiest way to understand code flow. In C++ you can print
276log statements using the LOG macro or printf(). In Java, you can print log
277statements using [android.util.Log](http://developer.android.com/reference/android/util/Log.html):
278
279`Log.d("sometag", "Reticulating splines progress = " + progress);`
280
281You can see these log statements using adb logcat:
282
283```shell
284adb logcat...01-14 11:08:53.373 22693 23070 D sometag: Reticulating splines progress = 0.99
285```
286
287You can debug Java or C++ code. To debug C++ code, use one of the
288following commands:
289
290```shell
291build/android/adb_gdb_content_shell
292build/android/adb_gdb_chrome_public
293build/android/adb_gdb_android_webview_shell http://example.com
294```
295
296See [Debugging Chromium on Android](https://www.chromium.org/developers/how-tos/debugging-on-android)
297for more on debugging, including how to debug Java code.
298
299### Testing
300
301For information on running tests, see [android\_test\_instructions.md](https://chromium.googlesource.com/chromium/src/+/master/docs/android_test_instructions.md).
302
303### Faster Edit/Deploy (GN only)
304
305GN's "incremental install" uses reflection and side-loading to speed up the edit
306& deploy cycle (normally < 10 seconds).
307
308* Make sure to set` is_component_build = true `in your GN args
309* All apk targets have \*`_incremental` targets defined (e.g.
310 `chrome_public_apk_incremental`)
311
312Here's an example:
313
314```shell
315ninja -C out/Default chrome_public_apk_incremental
316out/Default/bin/install_chrome_public_apk_incremental -v
317```
318
319For gunit tests (note that run_*_incremental automatically add
320--fast-local-dev when calling test\_runner.py):
321
322```shell
323ninja -C out/Default base_unittests_incremental
324out/Default/bin/run_base_unittests_incremental
325```
326
327For instrumentation tests:
328
329```shell
330ninja -C out/Default chrome_public_test_apk_incremental
331out/Default/bin/run_chrome_public_test_apk_incremental
332```
333
334To uninstall:
335
336```shell
337out/Default/bin/install_chrome_public_apk_incremental -v --uninstall
338```
339
340### Miscellaneous
341
342#### Rebuilding libchrome.so for a particular release
343
yfriedman9b4327b2016-05-04 16:36:24344These instructions are only necessary for Chrome 51 and earlier.
345
tfarinaa68eb902016-04-12 19:43:05346In the case where you want to modify the native code for an existing
347release of Chrome for Android (v25+) you can do the following steps.
348Note that in order to get your changes into the official release, you'll
349need to send your change for a codereview using the regular process for
350committing code to chromium.
351
3521. Open Chrome on your Android device and visit chrome://version
3532. Copy down the id listed next to "Build ID:"
3543. Go to
355 [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)
3564. Download the listed files and follow the steps in the README.