dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 1 | # Checking out and building Cast for Android |
| 2 | |
| 3 | **Note**: it is **not possible** to build a binary functionally |
| 4 | equivalent to a Chromecast. This is to build a single-page content |
| 5 | embedder with similar functionality to Cast products. |
| 6 | |
| 7 | ## Instructions for Google Employees |
| 8 | |
| 9 | Are you a Google employee? See |
| 10 | [go/building-android-cast](https://goto.google.com/building-android-cast) instead. |
| 11 | |
| 12 | [TOC] |
| 13 | |
| 14 | ## System requirements |
| 15 | |
Bruce Dawson | c266172 | 2024-06-12 19:44:29 | [diff] [blame] | 16 | * An x86-64 machine running Linux with at least 8GB of RAM. More than 16GB is |
| 17 | highly recommended. |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 18 | * At least 100GB of free disk space. |
| 19 | * You must have Git and Python installed already. |
| 20 | |
| 21 | Most development is done on Ubuntu. Other distros may or may not work; |
Tom Anderson | 93e49e49 | 2019-12-23 19:55:37 | [diff] [blame] | 22 | see the [Linux instructions](linux/build_instructions.md) for some suggestions. |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 23 | |
| 24 | Building the Android client on Windows or Mac is not supported and doesn't work. |
| 25 | |
| 26 | ## Install `depot_tools` |
| 27 | |
| 28 | Clone the `depot_tools` repository: |
| 29 | |
| 30 | ```shell |
| 31 | $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git |
| 32 | ``` |
| 33 | |
| 34 | Add `depot_tools` to the end of your PATH (you will probably want to put this |
| 35 | in your `~/.bashrc` or `~/.zshrc`). Assuming you cloned `depot_tools` |
| 36 | to `/path/to/depot_tools`: |
| 37 | |
| 38 | ```shell |
| 39 | $ export PATH="$PATH:/path/to/depot_tools" |
| 40 | ``` |
| 41 | |
| 42 | ## Get the code |
| 43 | |
| 44 | Create a `chromium` directory for the checkout and change to it (you can call |
| 45 | this whatever you like and put it wherever you like, as |
| 46 | long as the full path has no spaces): |
| 47 | |
| 48 | ```shell |
| 49 | $ mkdir ~/chromium && cd ~/chromium |
| 50 | $ fetch --nohooks android |
| 51 | ``` |
| 52 | |
| 53 | If you don't want the full repo history, you can save a lot of time by |
| 54 | adding the `--no-history` flag to `fetch`. |
| 55 | |
| 56 | Expect the command to take 30 minutes on even a fast connection, and many |
| 57 | hours on slower ones. |
| 58 | |
| 59 | If you've already installed the build dependencies on the machine (from another |
| 60 | checkout, for example), you can omit the `--nohooks` flag and `fetch` |
| 61 | will automatically execute `gclient runhooks` at the end. |
| 62 | |
| 63 | When `fetch` completes, it will have created a hidden `.gclient` file and a |
| 64 | directory called `src` in the working directory. The remaining instructions |
| 65 | assume you have switched to the `src` directory: |
| 66 | |
| 67 | ```shell |
| 68 | $ cd src |
| 69 | ``` |
| 70 | |
| 71 | ### Converting an existing Linux checkout |
| 72 | |
| 73 | If you have an existing Linux checkout, you can add Android support by |
| 74 | appending `target_os = ['android']` to your `.gclient` file (in the |
| 75 | directory above `src`): |
| 76 | |
| 77 | ```shell |
| 78 | $ echo "target_os = [ 'android' ]" >> ../.gclient |
| 79 | ``` |
| 80 | |
| 81 | Then run `gclient sync` to pull the new Android dependencies: |
| 82 | |
| 83 | ```shell |
| 84 | $ gclient sync |
| 85 | ``` |
| 86 | |
| 87 | (This is the only difference between `fetch android` and `fetch chromium`.) |
| 88 | |
| 89 | ### Install additional build dependencies |
| 90 | |
| 91 | Once you have checked out the code, run |
| 92 | |
| 93 | ```shell |
Ho Cheung | fd3ed27 | 2023-01-07 02:40:24 | [diff] [blame] | 94 | $ build/install-build-deps.sh --android |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 95 | ``` |
| 96 | |
| 97 | to get all of the dependencies you need to build on Linux, *plus* all of the |
| 98 | Android-specific dependencies (you need some of the regular Linux dependencies |
| 99 | because an Android build includes a bunch of the Linux tools and utilities). |
| 100 | |
| 101 | ### Run the hooks |
| 102 | |
| 103 | Once you've run `install-build-deps` at least once, you can now run the |
| 104 | Chromium-specific hooks, which will download additional binaries and other |
| 105 | things you might need: |
| 106 | |
| 107 | ```shell |
| 108 | $ gclient runhooks |
| 109 | ``` |
| 110 | |
| 111 | *Optional*: You can also [install API |
| 112 | keys](https://www.chromium.org/developers/how-tos/api-keys) if you want your |
| 113 | build to talk to some Google services, but this is not necessary for most |
| 114 | development and testing purposes. |
| 115 | |
| 116 | ## Setting up the build |
| 117 | |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 118 | Chromium uses [Ninja](https://ninja-build.org) as its main build tool along with |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 119 | a tool called [GN](https://gn.googlesource.com/gn/+/main/docs/quick_start.md) |
Tom Bridgwater | eef40154 | 2018-08-17 00:54:43 | [diff] [blame] | 120 | to generate `.ninja` files. You can create any number of *build directories* |
| 121 | with different configurations. To create a build directory which builds Chrome |
| 122 | for Android, run: |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 123 | |
| 124 | ```shell |
mark a. foltz | 06a88b1 | 2022-07-19 18:43:27 | [diff] [blame] | 125 | $ gn gen --args='target_os="android" is_cast_android=true' out/Default |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 126 | ``` |
| 127 | |
| 128 | * 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). |
| 134 | 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 |
Andrew Williams | bbc1a1e | 2021-07-21 01:51:22 | [diff] [blame] | 137 | [quick start guide](https://gn.googlesource.com/gn/+/main/docs/quick_start.md). |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 138 | |
| 139 | Also be aware that some scripts (e.g. `tombstones.py`, `adb_gdb.py`) |
| 140 | require you to set `CHROMIUM_OUTPUT_DIR=out/Default`. |
| 141 | |
Andrew Williams | 54da9cc | 2024-01-09 17:32:23 | [diff] [blame] | 142 | ### Faster builds |
| 143 | |
| 144 | This section contains some things you can change to speed up your builds, |
| 145 | sorted so that the things that make the biggest difference are first. |
| 146 | |
| 147 | #### Use Reclient |
| 148 | |
| 149 | *** note |
Jenna Himawan | 4913cb8 | 2025-02-05 15:42:43 | [diff] [blame] | 150 | **Warning:** If you are a Google employee, do not follow the Reclient instructions |
| 151 | in this section. Set up remote execution as described in |
| 152 | [go/building-android-chrome](https://goto.google.com/building-android-chrome) |
Andrew Williams | 54da9cc | 2024-01-09 17:32:23 | [diff] [blame] | 153 | instead. |
| 154 | *** |
| 155 | |
| 156 | Chromium's build can be sped up significantly by using a remote execution system |
| 157 | compatible with [REAPI](https://github.com/bazelbuild/remote-apis). This allows |
| 158 | you to benefit from remote caching and executing many build actions in parallel |
| 159 | on a shared cluster of workers. |
| 160 | |
| 161 | To use Reclient, follow the corresponding |
| 162 | [Linux build instructions](linux/build_instructions.md#use-reclient). |
| 163 | |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 164 | ## Build cast\_shell\_apk |
| 165 | |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 166 | Build `cast_browser_apk` with Ninja using the command: |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 167 | |
| 168 | ```shell |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 169 | $ autoninja -C out/Default cast_browser_apk |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 170 | ``` |
| 171 | |
Dirk Pranke | 8bd55f2 | 2018-10-24 21:22:10 | [diff] [blame] | 172 | (`autoninja` is a wrapper that automatically provides optimal values for the |
| 173 | arguments passed to `ninja`.) |
| 174 | |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 175 | ## Installing and Running `cast_browser_apk` on a device |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 176 | |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 177 | ### Plug in your Android device |
| 178 | |
| 179 | Make sure your Android device is plugged in via USB, and USB Debugging |
| 180 | is enabled. |
| 181 | |
| 182 | To enable USB Debugging: |
| 183 | |
| 184 | * Navigate to Settings \> About Phone \> Build number |
| 185 | * Click 'Build number' 7 times |
| 186 | * Now navigate back to Settings \> Developer Options |
| 187 | * Enable 'USB Debugging' and follow the prompts |
| 188 | |
| 189 | You may also be prompted to allow access to your PC once your device is |
| 190 | plugged in. |
| 191 | |
| 192 | You can check if the device is connected by running: |
| 193 | |
| 194 | ```shell |
Yun Liu | f57cceaf | 2019-03-18 21:31:23 | [diff] [blame] | 195 | third_party/android_sdk/public/platform-tools/adb devices |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 196 | ``` |
| 197 | |
| 198 | Which prints a list of connected devices. If not connected, try |
| 199 | unplugging and reattaching your device. |
| 200 | |
| 201 | ### Build the APK |
| 202 | |
| 203 | ```shell |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 204 | autoninja -C out/Release cast_browser_apk |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 205 | ``` |
| 206 | |
| 207 | And deploy it to your Android device: |
| 208 | |
| 209 | ```shell |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 210 | out/Default/bin/cast_browser_apk install |
Andrew Grieve | c81af4a | 2017-07-26 18:02:13 | [diff] [blame] | 211 | # Or to install and run: |
Simeon Anfinrud | 43f47b7 | 2024-09-26 22:57:56 | [diff] [blame] | 212 | out/Default/bin/cast_browser_apk run "http://google.com" |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 213 | ``` |
| 214 | |
| 215 | The app will appear on the device as "Chromium". |
| 216 | |
dpranke | c641a534 | 2017-04-04 02:35:01 | [diff] [blame] | 217 | ### Testing |
| 218 | |
Ken Rockot | 35028ca | 2019-05-30 18:50:45 | [diff] [blame] | 219 | For information on running tests, see |
| 220 | [Android Test Instructions](testing/android_test_instructions.md). |