| OLD | NEW |
| 1 # Android Build Instructions | 1 # Android Build Instructions |
| 2 | 2 |
| 3 **See also [the old version of this page](old_android_build_instructions.md).** |
| 4 |
| 5 Google employee? See [go/building-chrome](https://goto.google.com/building-chrom
e) instead. |
| 6 |
| 3 [TOC] | 7 [TOC] |
| 4 | 8 |
| 5 ## Prerequisites | 9 ## System requirements |
| 6 | 10 |
| 7 A Linux build machine capable of building [Chrome for | 11 * A 64-bit Intel machine running Linux with at least 8GB of RAM. More |
| 8 Linux](https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_
instructions_prerequisites.md). | 12 than 16GB is highly recommended. |
| 9 Other (Mac/Windows) platforms are not supported for Android. | 13 * At least 100GB of free disk space. |
| 14 * You must have Git and Python installed already. |
| 10 | 15 |
| 11 ## Getting the code | 16 Most development is done on Ubuntu. Other distros may or may not work; |
| 17 see the [linux instructions](linux_build_instructions.md) for some suggestions. |
| 12 | 18 |
| 13 First, check out and install the [depot\_tools | 19 Building the Android client on Windows or Mac is not supported and doesn't work. |
| 14 package](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_t
ools/docs/html/depot_tools_tutorial.html#_setting_up). | |
| 15 | 20 |
| 16 Then, if you have no existing checkout, create your source directory and | 21 ## Install `depot_tools` |
| 17 get the code: | |
| 18 | 22 |
| 19 ```shell | 23 Clone the depot_tools repository: |
| 20 mkdir ~/chromium && cd ~/chromium | 24 |
| 21 fetch --nohooks android # This will take 30 minutes on a fast connection | 25 $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 22 ``` | 26 |
| 27 Add depot_tools to the end of your PATH (you will probably want to put this |
| 28 in your ~/.bashrc or ~/.zshrc). Assuming you cloned depot_tools |
| 29 to /path/to/depot_tools: |
| 30 |
| 31 $ export PATH=$PATH:/path/to/depot_tools |
| 32 |
| 33 ## Get the code |
| 34 |
| 35 Create a chromium directory for the checkout and change to it (you can call |
| 36 this whatever you like and put it wherever you like, as |
| 37 long as the full path has no spaces): |
| 38 |
| 39 $ mkdir ~/chromium && cd ~/chromium |
| 40 $ fetch --nohooks android |
| 41 |
| 42 If you don't want the full repo history, you can save a lot of time by |
| 43 adding the `--no-history` flag to fetch. |
| 44 |
| 45 Expect the command to take 30 minutes on even a fast connection, and many |
| 46 hours on slower ones. |
| 47 |
| 48 If you've already installed the build dependencies on the machine (from another |
| 49 checkout, for example), you can omit the `--nohooks` flag and fetch |
| 50 will automatically execute `gclient runhooks` at the end. |
| 51 |
| 52 When fetch completes, it will have created a directory called `src`. |
| 53 The remaining instructions assume you are now in that directory: |
| 54 |
| 55 $ cd src |
| 56 |
| 57 ### Converting an existing Linux checkout |
| 23 | 58 |
| 24 If you have an existing Linux checkout, you can add Android support by | 59 If you have an existing Linux checkout, you can add Android support by |
| 25 appending `target_os = ['android']` to your .gclient file (in the | 60 appending `target_os = ['android']` to your .gclient file (in the |
| 26 directory above src): | 61 directory above src): |
| 27 | 62 |
| 28 ```shell | 63 $ echo "target_os = [ 'android' ]" >> ../.gclient |
| 29 cat > .gclient <<EOF | |
| 30 solutions = [ ...existing stuff in here... ] | |
| 31 target_os = [ 'android' ] # Add this to get Android stuff checked out. | |
| 32 EOF | |
| 33 ``` | |
| 34 | 64 |
| 35 Then run gclient sync to get the Android stuff checked out: | 65 Then run gclient sync to pull the new Android dependencies: |
| 36 | 66 |
| 37 ```shell | 67 gclient sync |
| 38 gclient sync | |
| 39 ``` | |
| 40 | 68 |
| 41 ## (Optional) Check out LKGR | 69 (This is actually the difference between `fetch android` and `fetch chromium`). |
| 42 | 70 |
| 43 If you want a single build of Chromium in a known good state, sync to | 71 ### Install additional build dependencies |
| 44 the 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 | 72 |
| 48 ```shell | 73 Once you have checked out the code, run |
| 49 gclient sync --nohooks -r <lkgr-sha1> | |
| 50 ``` | |
| 51 | 74 |
| 52 This is not needed for a typical developer workflow; only for one-time | 75 build/install-build-deps-android.sh |
| 53 builds of Chromium. | |
| 54 | 76 |
| 55 ## Configure GN | 77 to get all of the dependencies you need to build on Linux *plus* all of the |
| 78 Android-specific dependencies (you need some of the regular Linux dependencies |
| 79 because an Android build builds a bunch of the Linux tools and utilities). |
| 56 | 80 |
| 57 Create a build directory and set the build flags with: | 81 ### Run the hooks |
| 58 | 82 |
| 59 ```shell | 83 Once you've run `install-build-deps` at least once, you can now run the |
| 60 gn args out/Default | 84 chromium-specific hooks, which will download additional binaries and other |
| 61 ``` | 85 things you might need: |
| 62 | 86 |
| 63 You can replace out/Default with another name you choose inside the out | 87 $ gclient runhooks |
| 64 directory. | |
| 65 | 88 |
| 66 Also be aware that some scripts (e.g. tombstones.py, adb_gdb.py) | 89 *Optional*: You can also [install API keys](https://www.chromium.org/developers/
how-tos/api-keys) |
| 67 require you to set `CHROMIUM_OUTPUT_DIR=out/Default`. | 90 if you want to talk to some of the Google services, but this is not necessary |
| 91 for most development and testing purposes. |
| 68 | 92 |
| 69 This command will bring up your editor with the GN build args. In this | 93 ### Configure the JDK |
| 70 file add: | |
| 71 | |
| 72 ``` | |
| 73 target_os = "android" | |
| 74 target_cpu = "arm" # (default) | |
| 75 is_debug = true # (default) | |
| 76 | |
| 77 # Other args you may want to set: | |
| 78 is_component_build = true | |
| 79 is_clang = true | |
| 80 symbol_level = 1 # Faster build with fewer symbols. -g1 rather than -g2 | |
| 81 enable_incremental_javac = true # Much faster; experimental | |
| 82 ``` | |
| 83 | |
| 84 You can also specify `target_cpu` values of "x86" and "mipsel". Re-run | |
| 85 gn args on that directory to edit the flags in the future. See the [GN | |
| 86 build | |
| 87 configuration](https://www.chromium.org/developers/gn-build-configuration) | |
| 88 page for other flags you may want to set. | |
| 89 | |
| 90 ### Install build dependencies | |
| 91 | |
| 92 Update the system packages required to build by running: | |
| 93 | |
| 94 ```shell | |
| 95 ./build/install-build-deps-android.sh | |
| 96 ``` | |
| 97 | 94 |
| 98 Make also sure that OpenJDK 1.7 is selected as default: | 95 Make also sure that OpenJDK 1.7 is selected as default: |
| 99 | 96 |
| 100 `sudo update-alternatives --config javac` | 97 `sudo update-alternatives --config javac` |
| 101 `sudo update-alternatives --config java` | 98 `sudo update-alternatives --config java` |
| 102 `sudo update-alternatives --config javaws` | 99 `sudo update-alternatives --config javaws` |
| 103 `sudo update-alternatives --config javap` | 100 `sudo update-alternatives --config javap` |
| 104 `sudo update-alternatives --config jar` | 101 `sudo update-alternatives --config jar` |
| 105 `sudo update-alternatives --config jarsigner` | 102 `sudo update-alternatives --config jarsigner` |
| 106 | 103 |
| 107 ### Synchronize sub-directories. | 104 ## Setting up the Build |
| 108 | 105 |
| 109 ```shell | 106 Chromium uses [Ninja](https://ninja-build.org) as its main build tool, and |
| 110 gclient sync | 107 a tool called [GN](../tools/gn/docs/quick_start.md) to generate |
| 111 ``` | 108 the .ninja files to do the build. To create a build directory configured |
| 109 to build Android, run: |
| 112 | 110 |
| 113 ## Build and install the APKs | 111 $ gn gen '--args="target_os="android"' out/Default |
| 112 |
| 113 * You only have to do run this command once, it will self-update the build |
| 114 files as needed after that. |
| 115 * You can replace `out/Default` with another directory name, but we recommend |
| 116 it should still be a subdirectory of `out`. |
| 117 * To specify build parameters for GN builds, including release settings, |
| 118 see [GN build configuration](https://www.chromium.org/developers/gn-build-conf
iguration). |
| 119 The default will be a debug component build matching the current host |
| 120 operating system and CPU. |
| 121 * For more info on GN, run `gn help` on the command line or read the |
| 122 [quick start guide](../tools/gn/docs/quick_start.md). |
| 123 |
| 124 Also be aware that some scripts (e.g. tombstones.py, adb_gdb.py) |
| 125 require you to set `CHROMIUM_OUTPUT_DIR=out/Default`. |
| 126 |
| 127 ## Build Chromium |
| 128 |
| 129 Build Chromium with Ninja using the command: |
| 130 |
| 131 $ ninja -C out/Default chrome_public_apk |
| 132 |
| 133 You can get a list of all of the other build targets from GN by running |
| 134 `gn ls out/Default` from the command line. To compile one, pass to Ninja |
| 135 the GN label with no preceding "//" (so for `//chrome/test:unit_tests` |
| 136 use ninja -C out/Default chrome/test:unit_tests`). |
| 137 ## Installing and Running Chromium on a device |
| 114 | 138 |
| 115 If the `adb_install_apk.py` script below fails, make sure aapt is in | 139 If the `adb_install_apk.py` script below fails, make sure aapt is in |
| 116 your PATH. If not, add aapt's path to your PATH environment variable (it | 140 your PATH. If not, add aapt's path to your PATH environment variable (it |
| 117 should be | 141 should be |
| 118 `/path/to/src/third_party/android_tools/sdk/build-tools/{latest_version}/`). | 142 `/path/to/src/third_party/android_tools/sdk/build-tools/{latest_version}/`). |
| 119 | 143 |
| 120 Prepare the environment: | 144 Prepare the environment: |
| 121 | 145 |
| 122 ```shell | 146 ```shell |
| 123 . build/android/envsetup.sh | 147 . build/android/envsetup.sh |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 ninja -C out/Default chrome_public_test_apk_incremental | 307 ninja -C out/Default chrome_public_test_apk_incremental |
| 284 out/Default/bin/run_chrome_public_test_apk_incremental | 308 out/Default/bin/run_chrome_public_test_apk_incremental |
| 285 ``` | 309 ``` |
| 286 | 310 |
| 287 To uninstall: | 311 To uninstall: |
| 288 | 312 |
| 289 ```shell | 313 ```shell |
| 290 out/Default/bin/install_chrome_public_apk_incremental -v --uninstall | 314 out/Default/bin/install_chrome_public_apk_incremental -v --uninstall |
| 291 ``` | 315 ``` |
| 292 | 316 |
| 293 ### Miscellaneous | 317 ## Tips, tricks, and troubleshooting |
| 294 | 318 |
| 295 #### Rebuilding libchrome.so for a particular release | 319 ### Rebuilding libchrome.so for a particular release |
| 296 | 320 |
| 297 These instructions are only necessary for Chrome 51 and earlier. | 321 These instructions are only necessary for Chrome 51 and earlier. |
| 298 | 322 |
| 299 In the case where you want to modify the native code for an existing | 323 In the case where you want to modify the native code for an existing |
| 300 release of Chrome for Android (v25+) you can do the following steps. | 324 release of Chrome for Android (v25+) you can do the following steps. |
| 301 Note that in order to get your changes into the official release, you'll | 325 Note that in order to get your changes into the official release, you'll |
| 302 need to send your change for a codereview using the regular process for | 326 need to send your change for a codereview using the regular process for |
| 303 committing code to chromium. | 327 committing code to chromium. |
| 304 | 328 |
| 305 1. Open Chrome on your Android device and visit chrome://version | 329 1. Open Chrome on your Android device and visit chrome://version |
| 306 2. Copy down the id listed next to "Build ID:" | 330 2. Copy down the id listed next to "Build ID:" |
| 307 3. Go to | 331 3. Go to |
| 308 [http://storage.googleapis.com/chrome-browser-components/BUILD\_ID\_FROM\_ST
EP\_2/index.html](http://storage.googleapis.com/chrome-browser-components/BUILD_
ID_FROM_STEP_2/index.html) | 332 [http://storage.googleapis.com/chrome-browser-components/BUILD\_ID\_FROM\_ST
EP\_2/index.html](http://storage.googleapis.com/chrome-browser-components/BUILD_
ID_FROM_STEP_2/index.html) |
| 309 4. Download the listed files and follow the steps in the README. | 333 4. Download the listed files and follow the steps in the README. |
| OLD | NEW |