AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 1 | # Getting started |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | This page describes how to set up your workstation to check out source code, |
| 6 | make simple changes in Android Studio, and upload commits to Gerrit for review. |
| 7 | |
| 8 | This page does **not** cover best practices for the content of changes. Please |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 9 | see [Life of a Jetpack Feature](/docs/loaf.md) for details on |
AndroidX Core Team | 76f6545 | 2024-01-02 11:39:57 -0800 | [diff] [blame] | 10 | creating and releasing a library or |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 11 | [API Guidelines](/docs/api_guidelines/index.md) for best |
AndroidX Core Team | 76f6545 | 2024-01-02 11:39:57 -0800 | [diff] [blame] | 12 | practices regarding library development. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 13 | |
| 14 | ## Workstation setup {#setup} |
| 15 | |
AndroidX Core Team | cc1e9b1 | 2022-06-27 13:10:24 -0700 | [diff] [blame] | 16 | This section will help you install the `repo` tool, which is used for Git branch |
| 17 | and commit management. If you want to learn more about `repo`, see the |
| 18 | [Repo Command Reference](https://source.android.com/setup/develop/repo). |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 19 | |
AndroidX Core Team | 95040f7 | 2024-10-10 14:31:18 -0700 | [diff] [blame] | 20 | NOTE The `repo` tool uses Git submodules under the hood, and it is possible to |
| 21 | skip using the tool in favor of using submodules directly. If you prefer to use |
| 22 | submodules, look for notes anywhere that `repo` is mentioned in this document. |
| 23 | Submodule users can skip Workstation setup. |
| 24 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 25 | ### Linux and MacOS {#setup-linux-mac} |
| 26 | |
| 27 | First, download `repo` using `curl`. |
| 28 | |
| 29 | ```shell |
| 30 | test -d ~/bin || mkdir ~/bin |
| 31 | curl https://storage.googleapis.com/git-repo-downloads/repo \ |
| 32 | > ~/bin/repo && chmod 700 ~/bin/repo |
| 33 | ``` |
| 34 | |
AndroidX Core Team | 685fbcd | 2022-01-10 14:18:55 -0800 | [diff] [blame] | 35 | Then, modify `~/.zshrc` (or `~/.bash_profile` if using `bash`) to ensure you can |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 36 | find local binaries from the command line. We assume you're using `zsh`, but the |
AndroidX Core Team | 685fbcd | 2022-01-10 14:18:55 -0800 | [diff] [blame] | 37 | following should work with `bash` as well. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 38 | |
| 39 | ```shell |
| 40 | export PATH=~/bin:$PATH |
| 41 | ``` |
| 42 | |
AndroidX Core Team | 693e3f8 | 2024-05-17 05:25:53 -0700 | [diff] [blame] | 43 | > NOTE: When using quotes (`"~/bin"`), `~` does not expand and the path is |
| 44 | > invalid. (Possibly `bash` only?) |
| 45 | |
AndroidX Core Team | 6827451 | 2022-04-28 13:10:15 -0700 | [diff] [blame] | 46 | Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using |
| 47 | `bash`) aliasing the `repo` command to run with `python3`: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 48 | |
| 49 | ```shell |
| 50 | # Force repo to run with Python3 |
| 51 | function repo() { |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 52 | command python3 ~/bin/repo $@ |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 53 | } |
| 54 | ``` |
| 55 | |
AndroidX Core Team | 6827451 | 2022-04-28 13:10:15 -0700 | [diff] [blame] | 56 | Finally, you will need to either start a new terminal session or run `source |
| 57 | ~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes. |
| 58 | |
| 59 | > NOTE: If you encounter the following warning about Python 2 being no longer |
| 60 | > supported, you will need to install Python 3 from the |
| 61 | > [official website](https://www.python.org). |
| 62 | > |
| 63 | > ```shell {.bad} |
| 64 | > repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+. |
| 65 | > ``` |
| 66 | |
| 67 | > NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error: |
| 68 | > |
| 69 | > ```shell {.bad} |
| 70 | > Downloading Repo source from https://gerrit.googlesource.com/git-repo |
| 71 | > fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle |
| 72 | > fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997) |
| 73 | > ``` |
| 74 | > |
AndroidX Core Team | f95fde7 | 2024-05-07 11:03:03 -0700 | [diff] [blame] | 75 | > Run the `Install Certificates.command` in the Python folder of Application |
| 76 | > (e.g. `/Applications/Python\ 3.11/Install\ Certificates.command`). For more |
| 77 | > information about SSL/TLS certificate validation, you can read the "Important |
| 78 | > Information" displayed during Python installation. |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 79 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 80 | ### Windows {#setup-win} |
| 81 | |
| 82 | Sorry, Windows is not a supported platform for AndroidX development. |
| 83 | |
| 84 | ## Set up access control {#access} |
| 85 | |
| 86 | ### Authenticate to AOSP Gerrit {#access-gerrit} |
| 87 | |
| 88 | Before you can upload changes, you will need to associate your Google |
| 89 | credentials with the AOSP Gerrit code review system by signing in to |
| 90 | [android-review.googlesource.com](https://android-review.googlesource.com) at |
| 91 | least once using the account you will use to submit patches. |
| 92 | |
| 93 | Next, you will need to |
AndroidX Core Team | 1770ed7 | 2024-08-12 10:18:54 -0700 | [diff] [blame] | 94 | [set up authentication](https://android.googlesource.com/new-password). |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 95 | This will give you a shell command to update your local Git cookies, which will |
| 96 | allow you to upload changes. |
| 97 | |
| 98 | Finally, you will need to accept the |
| 99 | [CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement). |
| 100 | |
| 101 | ## Check out the source {#source} |
| 102 | |
| 103 | Like ChromeOS, Chromium, and the Android build system, we develop in the open as |
| 104 | much as possible. All feature development occurs in the public |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 105 | [androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 106 | branch of the Android Open Source Project. |
| 107 | |
AndroidX Core Team | 95040f7 | 2024-10-10 14:31:18 -0700 | [diff] [blame] | 108 | As of 2024/10/10, you will need about XXX GB for a clean checkout or YYY GB for |
| 109 | a fully-built checkout. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 110 | |
| 111 | ### Synchronize the branch {#source-checkout} |
| 112 | |
AndroidX Core Team | 4e1909a | 2021-10-20 15:04:04 +0000 | [diff] [blame] | 113 | Use the following commands to check out your branch. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 114 | |
AndroidX Core Team | f5f77ab | 2021-01-05 10:56:15 -0500 | [diff] [blame] | 115 | #### Public main development branch {#androidx-main} |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 116 | |
| 117 | All development should occur in this branch unless otherwise specified by the |
| 118 | AndroidX Core team. |
| 119 | |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 120 | The following command will check out the public main development branch: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 121 | |
| 122 | ```shell |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 123 | mkdir androidx-main && cd androidx-main |
alanv | 7ae4894 | 2022-09-27 13:53:32 -0700 | [diff] [blame] | 124 | repo init -u https://android.googlesource.com/platform/manifest \ |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 125 | -b androidx-main --partial-clone --clone-filter=blob:limit=10M |
AndroidX Core Team | 95040f7 | 2024-10-10 14:31:18 -0700 | [diff] [blame] | 126 | repo sync -c -j32 |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 127 | ``` |
| 128 | |
| 129 | NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED` |
| 130 | you may need to install Python3 and boot strap the SSL certificates in the |
| 131 | included version of pip. You can execute `Install Certificates.command` under |
| 132 | `/Applications/Python 3.6/` to do so. |
| 133 | |
AndroidX Core Team | f74ae23 | 2022-04-25 11:17:51 -0400 | [diff] [blame] | 134 | NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg" |
| 135 | failed with exit status -6` with cause `md_enable: algorithm 10 not available` |
| 136 | you may need to install a build of `gpg` that supports SHA512, such as the |
| 137 | latest version available from [Homebrew](https://brew.sh/) using `brew install |
| 138 | gpg`. |
| 139 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 140 | ### Increase Git rename limit {#source-config} |
| 141 | |
| 142 | To ensure `git` can detect diffs and renames across significant changes (namely, |
| 143 | the `androidx.*` package rename), we recommend that you set the following `git |
| 144 | config` properties: |
| 145 | |
| 146 | ```shell |
| 147 | git config --global merge.renameLimit 999999 |
| 148 | git config --global diff.renameLimit 999999 |
| 149 | ``` |
| 150 | |
alanv | 207674d | 2022-06-14 11:20:52 -0700 | [diff] [blame] | 151 | ### Set up Git file exclusions {#source-exclude} |
| 152 | |
| 153 | Mac users should consider adding `.DS_Store` to a global `.gitignore` file to |
| 154 | avoid accidentally checking in local metadata files: |
| 155 | |
| 156 | ```shell |
| 157 | echo .DS_Store>>~/.gitignore |
| 158 | git config --global core.excludesFile '~/.gitignore' |
| 159 | ``` |
| 160 | |
| 161 | ### To check out older sources, use the superproject {#source-historical} |
AndroidX Core Team | c2e3ad5 | 2021-08-17 13:40:01 -0400 | [diff] [blame] | 162 | |
| 163 | The |
| 164 | [git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main) |
| 165 | contains a history of the matching exact commits of each git repository over |
| 166 | time, and it can be |
| 167 | [checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules) |
| 168 | |
alanv | e9101e4 | 2022-01-28 12:05:11 -0800 | [diff] [blame] | 169 | ### Troubleshooting |
| 170 | |
| 171 | > NOTE: If the repo manifest changes -- for example when we update the version |
| 172 | > of `platform-tools` by pointing it to a different git project -- you may see |
| 173 | > the following error during`repo sync`: |
| 174 | > |
| 175 | > ```shell |
| 176 | > error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree. |
| 177 | > ... |
| 178 | > error: Unable to fully sync the tree. |
| 179 | > error: Downloading network changes failed. |
| 180 | > ``` |
| 181 | > |
| 182 | > This indicates that Studio or some other process has made changes in the git |
| 183 | > project that has been replaced or removed. You can force `repo sync` to |
| 184 | > discard these changes and check out the correct git project by adding the |
| 185 | > `--force-sync` argument: |
| 186 | > |
| 187 | > ```shell |
| 188 | > repo sync -j32 --force-sync |
| 189 | > ``` |
| 190 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 191 | ## Explore source code from a browser {#code-search} |
| 192 | |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 193 | `androidx-main` has a publicly-accessible |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 194 | [code search](https://cs.android.com/androidx/platform/frameworks/support) that |
| 195 | allows you to explore all of the source code in the repository. Links to this |
AndroidX Core Team | 3758414 | 2021-02-25 17:58:46 +0000 | [diff] [blame] | 196 | URL may be shared on the public issue tracked and other external sites. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 197 | |
AndroidX Core Team | 110f54d | 2022-10-24 08:35:31 -0700 | [diff] [blame] | 198 | ### Custom search engine for `androidx-main` {#custom-search-engine} |
| 199 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 200 | We recommend setting up a custom search engine in Chrome as a faster (and |
| 201 | publicly-accessible) alternative to `cs/`. |
| 202 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 203 | 1. Open `chrome://settings/searchEngines` |
| 204 | 1. Click the `Add` button |
| 205 | 1. Enter a name for your search engine, ex. "AndroidX Code Search" |
| 206 | 1. Enter a keyword, ex. "csa" |
| 207 | 1. Enter the following URL: |
| 208 | `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport` |
| 209 | 1. Click the `Add` button |
| 210 | |
| 211 | Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a |
| 212 | query to search for, e.g. `AppCompatButton file:appcompat`, and press the |
| 213 | `Enter` key to get to the search result page. |
| 214 | |
| 215 | ## Develop in Android Studio {#studio} |
| 216 | |
| 217 | Library development uses a curated version of Android Studio to ensure |
| 218 | compatibility between various components of the development workflow. |
| 219 | |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 220 | From the `frameworks/support` directory, you can use `./studiow m` (short for |
| 221 | `ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the |
AndroidX Core Team | 23c5044 | 2021-05-18 13:03:40 -0400 | [diff] [blame] | 222 | correct version of Studio to work on the `main` set of androidx projects |
| 223 | (non-Compose Jetpack libraries). |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 224 | [studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow) |
| 225 | also supports several other arguments like `all` for other subsets of the |
AndroidX Core Team | 23c5044 | 2021-05-18 13:03:40 -0400 | [diff] [blame] | 226 | projects (run `./studiow` for help). |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 227 | |
| 228 | Next, open the `framework/support` project root from your checkout. If Studio |
| 229 | asks you which SDK you would like to use, select `Use project SDK`. Importing |
| 230 | projects may take a while, but once that finishes you can use Studio as you |
| 231 | normally would for application or library development -- right-click on a test |
| 232 | or sample to run or debug it, search through classes, and so on. |
| 233 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 234 | > NOTE: You should choose "Use project SDK" when prompted by Studio. If you |
| 235 | > picked "Android Studio SDK" by mistake, don't panic! You can fix this by |
| 236 | > opening `File > Project Structure > Platform Settings > SDKs` and manually |
| 237 | > setting the Android SDK home path to |
| 238 | > `<project-root>/prebuilts/fullsdk-<platform>`. |
| 239 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 240 | ### Troubleshooting {#studio-troubleshooting} |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 241 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 242 | * If you've updated to macOS Ventura and receive a "xcrun: error: invalid |
| 243 | active developer path" message when running Studio, reinstall Xcode using |
| 244 | `xcode-select --install`. If that does not work, you will need to download |
| 245 | Xcode. |
| 246 | * If you get a “Unregistered VCS root detected” message, click “Add root” to |
| 247 | enable the Git/VCS integration for Android Studio. |
| 248 | * If you see any errors (red underlines), click Gradle's elephant button in |
| 249 | the toolbar (or `File > Sync Project with Gradle Files`) and they should |
| 250 | resolve once the build completes. |
| 251 | * If you run `./studiow` with a new project set but you're still seeing the |
| 252 | old project set in `Project`, use `File > Sync Project with Gradle Files` to |
| 253 | force a re-sync. |
| 254 | * If Android Studio's UI looks scaled up, ex. twice the size it should be, you |
| 255 | may need to add the following line to your `studio64.vmoptions` file using |
| 256 | `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false` |
| 257 | * If you don't see a specific Gradle task listed in Studio's Gradle pane, |
| 258 | check the following: |
| 259 | * Studio might be running a different project subset than the one |
| 260 | intended. For example, `./studiow main` only loads the `main` set of |
| 261 | androidx projects; run `./studiow compose` to load the tasks specific to |
| 262 | Compose. |
| 263 | * Gradle tasks aren't being loaded. Under Studio's settings => |
| 264 | Experimental, make sure that "Do not build Gradle task list during |
| 265 | Gradle sync" is unchecked. Note that unchecking this can reduce Studio's |
| 266 | performance. |
AndroidX Core Team | 3df24a6 | 2022-05-20 06:22:30 -0700 | [diff] [blame] | 267 | |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 268 | If in the future you encounter unexpected errors in Studio and you want to check |
| 269 | for the possibility it is due to some incorrect settings or other generated |
| 270 | files, you can run `./studiow --clean main <project subset>` or `./studiow |
| 271 | --reinstall <project subset>` to clean generated files or reinstall Studio. |
| 272 | |
alanv | 07cfb5e | 2022-10-12 11:14:08 -0700 | [diff] [blame] | 273 | ### Enabling Compose `@Preview` annotation previews |
AndroidX Core Team | 6173c65 | 2022-05-19 20:43:28 +0000 | [diff] [blame] | 274 | |
alanv | 07cfb5e | 2022-10-12 11:14:08 -0700 | [diff] [blame] | 275 | Add the following dependencies to your project's `build.gradle`: |
AndroidX Core Team | 6173c65 | 2022-05-19 20:43:28 +0000 | [diff] [blame] | 276 | |
| 277 | ```groovy |
| 278 | dependencies { |
| 279 | implementation(project(":compose:ui:ui-tooling-preview")) |
| 280 | debugImplementation(project(":compose:ui:ui-tooling")) |
| 281 | } |
| 282 | ``` |
| 283 | |
alanv | 07cfb5e | 2022-10-12 11:14:08 -0700 | [diff] [blame] | 284 | Then, |
AndroidX Core Team | 6173c65 | 2022-05-19 20:43:28 +0000 | [diff] [blame] | 285 | [use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling). |
| 286 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 287 | ## Making changes {#changes} |
| 288 | |
AndroidX Core Team | 5c914c4 | 2021-02-08 17:22:57 +0000 | [diff] [blame] | 289 | Similar to Android framework development, library development should occur in |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 290 | CL-specific working branches. Use `repo` to create, upload, and abandon local |
| 291 | branches. Use `git` to manage changes within a local branch. |
| 292 | |
| 293 | ```shell |
| 294 | cd path/to/checkout/frameworks/support/ |
| 295 | repo start my_branch_name . |
| 296 | # make necessary code changes |
| 297 | # use git to commit changes |
| 298 | repo upload --cbr -t . |
| 299 | ``` |
| 300 | |
| 301 | The `--cbr` switch automatically picks the current repo branch for upload. The |
AndroidX Core Team | 0db91f0 | 2021-05-06 22:45:18 +0000 | [diff] [blame] | 302 | `-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You |
| 303 | can refer to the |
| 304 | [Android documentation](https://source.android.com/setup/create/coding-tasks#workflow) |
| 305 | for a high level overview of this basic workflow. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 306 | |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 307 | If you see the following prompt, choose `always`: |
| 308 | |
| 309 | ``` |
| 310 | Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)? |
| 311 | ``` |
| 312 | |
| 313 | If the upload succeeds, you'll see an output like: |
| 314 | |
| 315 | ``` |
| 316 | remote: |
| 317 | remote: New Changes: |
| 318 | remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates |
| 319 | remote: |
| 320 | ``` |
| 321 | |
| 322 | To edit your change, use `git commit --amend`, and re-upload. |
| 323 | |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 324 | NOTE If you encounter issues with `repo upload`, consider running upload with |
| 325 | trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These |
| 326 | logs can be helpful for reporting issues to the team that manages our git |
| 327 | servers. |
| 328 | |
AndroidX Core Team | 03b4da3 | 2021-03-10 23:20:41 +0000 | [diff] [blame] | 329 | NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to |
| 330 | skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be |
| 331 | hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo` |
| 332 | to use HTTP/1.1 with `git config --global http.version HTTP/1.1`. |
| 333 | |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 334 | ### Fixing Kotlin code style errors |
| 335 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 336 | `repo upload` automatically runs `ktfmt`, which will cause the upload to fail if |
| 337 | your code has style errors, which it reports on the command line like so: |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 338 | |
| 339 | ``` |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 340 | [FAILED] ktfmt_hook |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 341 | [path]/MessageListAdapter.kt:36:69: Missing newline before ")" |
| 342 | ``` |
| 343 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 344 | To find and fix these errors, you can run ktfmt locally, either in a console |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 345 | window or in the Terminal tool in Android Studio. Running in the Terminal tool |
| 346 | is preferable because it will surface links to your source files/lines so you |
| 347 | can easily navigate to the code to fix any problems. |
| 348 | |
| 349 | First, to run the tool and see all of the errors, run: |
| 350 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 351 | `./gradlew module:submodule:ktCheck` |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 352 | |
| 353 | where module/submodule are the names used to refer to the module you want to |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 354 | check, such as `navigation:navigation-common`. You can also run ktfmt on the |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 355 | entire project, but that takes longer as it is checking all active modules in |
| 356 | your project. |
| 357 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 358 | Many of the errors that ktfmt finds can be automatically fixed by running |
| 359 | ktFormat: |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 360 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 361 | `./gradlew module:submodule:ktFormat` |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 362 | |
AndroidX Core Team | f39d01e | 2024-06-04 13:43:37 -0700 | [diff] [blame] | 363 | ktFormat will report any remaining errors, but you can also run `ktCheck` again |
| 364 | at any time to see an updated list of the remaining errors. |
AndroidX Core Team | deda2cf | 2021-08-06 15:14:40 -0700 | [diff] [blame] | 365 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 366 | ## Building {#building} |
| 367 | |
| 368 | ### Modules and Maven artifacts {#modules-and-maven-artifacts} |
| 369 | |
| 370 | To build a specific module, use the module's `assemble` Gradle task. For |
| 371 | example, if you are working on `core` module use: |
| 372 | |
| 373 | ```shell |
| 374 | ./gradlew core:core:assemble |
| 375 | ``` |
| 376 | |
AndroidX Core Team | 03b4da3 | 2021-03-10 23:20:41 +0000 | [diff] [blame] | 377 | To make warnings fail your build (same as presubmit), use the `--strict` flag, |
| 378 | which our gradlew expands into a few correctness-related flags including |
AndroidX Core Team | 9d812cd | 2022-09-01 15:42:06 -0700 | [diff] [blame] | 379 | `-Pandroidx.validateNoUnrecognizedMessages`: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 380 | |
| 381 | ```shell |
AndroidX Core Team | 03b4da3 | 2021-03-10 23:20:41 +0000 | [diff] [blame] | 382 | ./gradlew core:core:assemble --strict |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 383 | ``` |
| 384 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 385 | To build every module and generate the local Maven repository artifact, use the |
| 386 | `createArchive` Gradle task: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 387 | |
| 388 | ```shell |
| 389 | ./gradlew createArchive |
| 390 | ``` |
| 391 | |
AndroidX Core Team | 03b4da3 | 2021-03-10 23:20:41 +0000 | [diff] [blame] | 392 | To run the complete build task that our build servers use, use the corresponding |
| 393 | shell script: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 394 | |
| 395 | ```shell |
AndroidX Core Team | 03b4da3 | 2021-03-10 23:20:41 +0000 | [diff] [blame] | 396 | ./busytown/androidx.sh |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 397 | ``` |
| 398 | |
| 399 | ### Attaching a debugger to the build |
| 400 | |
AndroidX Core Team | d5597b9 | 2022-08-09 10:33:00 -0700 | [diff] [blame] | 401 | Gradle tasks, including building a module, may be run or debugged from within |
| 402 | Android Studio. To start, you need to add the task as a run configuration: you |
| 403 | can do this manually by adding the corresponding task by clicking on the run |
| 404 | configuration dropdown, pressing |
| 405 | [`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html), |
| 406 | and adding the corresponding task. |
| 407 | |
| 408 | You can also run the task through the IDE from the terminal, by using the |
| 409 | [`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/) |
| 410 | feature - type in the task you want to run in the in-IDE terminal, and |
| 411 | `ctrl+enter` / `cmd+enter` to launch this through the IDE. This will |
| 412 | automatically add the configuration to the run configuration menu - you can then |
| 413 | cancel the task. |
| 414 | |
| 415 | Once the task has been added to the run configuration menu, you can start |
| 416 | debugging as with any other task by pressing the `debug` button. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 417 | |
| 418 | Note that debugging will not be available until Gradle sync has completed. |
| 419 | |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 420 | #### From the command line |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 421 | |
| 422 | Tasks may also be debugged from the command line, which may be useful if |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 423 | `./studiow` cannot run due to a Gradle task configuration issue. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 424 | |
AndroidX Core Team | 6173c65 | 2022-05-19 20:43:28 +0000 | [diff] [blame] | 425 | 1. From the Run dropdown in Studio, select "Edit Configurations". |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 426 | 1. Click the plus in the top left to create a new "Remote" configuration. Give |
| 427 | it a name and hit "Ok". |
| 428 | 1. Set breakpoints. |
| 429 | 1. Run your task with added flags: `./gradlew <your_task_here> |
| 430 | -Dorg.gradle.debug=true --no-daemon` |
| 431 | 1. Hit the "Debug" button to the right of the configuration dropdown to attach |
| 432 | to the process. |
| 433 | |
| 434 | #### Troubleshooting the debugger |
| 435 | |
| 436 | If you get a "Connection refused" error, it's likely because a gradle daemon is |
| 437 | still running on the port specified in the config, and you can fix this by |
| 438 | killing the running gradle daemons: |
| 439 | |
| 440 | ```shell |
| 441 | ./gradlew --stop |
| 442 | ``` |
| 443 | |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 444 | NOTE This is described in more detail in this |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 445 | [Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b). |
| 446 | |
| 447 | #### Attaching to an annotation processor |
| 448 | |
| 449 | Annotation processors run as part of the build, to debug them is similar to |
| 450 | debugging the build. |
| 451 | |
| 452 | For a Java project: |
| 453 | |
| 454 | ```shell |
| 455 | ./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true |
| 456 | ``` |
| 457 | |
| 458 | For a Kotlin project: |
| 459 | |
| 460 | ```shell |
| 461 | ./gradlew <your_project>:compileDebugKotlin --no-daemon --rerun-tasks -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=5005\,server=y\,suspend=n" |
| 462 | ``` |
| 463 | |
| 464 | ### Optional: Enabling internal menu in IntelliJ/Studio |
| 465 | |
| 466 | To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug |
| 467 | Android Lint checks and Metalava, you can enable the |
| 468 | [internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html) |
| 469 | which is typically used for plugin and IDE development. |
| 470 | |
| 471 | ### Reference documentation {#docs} |
| 472 | |
| 473 | Our reference docs (Javadocs and KotlinDocs) are published to |
| 474 | https://developer.android.com/reference/androidx/packages and may be built |
| 475 | locally. |
| 476 | |
| 477 | NOTE `./gradlew tasks` always has the canonical task information! When in doubt, |
| 478 | run `./gradlew tasks` |
| 479 | |
AndroidX Core Team | 76f6545 | 2024-01-02 11:39:57 -0800 | [diff] [blame] | 480 | #### Generate docs |
AndroidX Core Team | e1288a7 | 2021-09-03 12:30:13 -0700 | [diff] [blame] | 481 | |
| 482 | To build API reference docs for both Java and Kotlin source code using Dackka, |
| 483 | run the Gradle task: |
| 484 | |
| 485 | ``` |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 486 | ./gradlew docs |
AndroidX Core Team | e1288a7 | 2021-09-03 12:30:13 -0700 | [diff] [blame] | 487 | ``` |
| 488 | |
| 489 | Location of generated refdocs: |
| 490 | |
| 491 | * docs-public (what is published to DAC): |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 492 | `{androidx-main}/out/androidx/docs-public/build/docs` |
| 493 | * docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs` |
AndroidX Core Team | e1288a7 | 2021-09-03 12:30:13 -0700 | [diff] [blame] | 494 | |
AndroidX Core Team | d41eada | 2022-08-12 13:36:49 -0700 | [diff] [blame] | 495 | The generated docs are plain HTML pages with links that do not work locally. |
| 496 | These issues are fixed when the docs are published to DAC, but to preview a |
| 497 | local version of the docs with functioning links and CSS, run: |
| 498 | |
| 499 | ``` |
| 500 | python3 development/offlinifyDocs/offlinify_dackka_docs.py |
| 501 | ``` |
| 502 | |
| 503 | You will need to have the `bs4` Python package installed. The CSS used is not |
| 504 | the same as what will be used when the docs are published. |
| 505 | |
| 506 | By default, this command converts the tip-of-tree docs for all libraries. To see |
| 507 | more options, run: |
| 508 | |
| 509 | ``` |
| 510 | python3 development/offlinifyDocs/offlinify_dackka_docs.py --help |
| 511 | ``` |
| 512 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 513 | #### Release docs |
| 514 | |
| 515 | To build API reference docs for published artifacts formatted for use on |
| 516 | [d.android.com](http://d.android.com), run the Gradle command: |
| 517 | |
| 518 | ``` |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 519 | ./gradlew zipDocs |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 520 | ``` |
| 521 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 522 | This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This |
| 523 | command builds docs based on the version specified in |
AndroidX Core Team | 4e1909a | 2021-10-20 15:04:04 +0000 | [diff] [blame] | 524 | `{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses |
| 525 | the prebuilt checked into |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 526 | `{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We |
AndroidX Core Team | 4e1909a | 2021-10-20 15:04:04 +0000 | [diff] [blame] | 527 | colloquially refer to this two step process of (1) updating `docs-public` and |
| 528 | (2) checking in a prebuilt artifact into the prebuilts directory as |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 529 | [The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™). |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 530 | So, to build javadocs that will be published to |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 531 | https://developer.android.com/reference/androidx/packages, both of these steps |
| 532 | need to be completed. |
| 533 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 534 | ### Updating public APIs {#updating-public-apis} |
| 535 | |
| 536 | Public API tasks -- including tracking, linting, and verifying compatibility -- |
| 537 | are run under the following conditions based on the `androidx` configuration |
| 538 | block, evaluated in order: |
| 539 | |
| 540 | * `runApiTasks=Yes` => yes |
| 541 | * `runApiTasks=No` => no |
| 542 | * `toolingProject=true` => no |
| 543 | * `mavenVersion` or group version not set => no |
| 544 | * Has an existing `api/` directory => yes |
| 545 | * `publish=SNAPSHOT_AND_RELEASE` => yes |
| 546 | * Otherwise, no |
| 547 | |
| 548 | If you make changes to tracked public APIs, you will need to acknowledge the |
| 549 | changes by updating the `<component>/api/current.txt` and associated API files. |
| 550 | This is handled automatically by the `updateApi` Gradle task: |
| 551 | |
| 552 | ```shell |
| 553 | # Run updateApi for all modules. |
| 554 | ./gradlew updateApi |
| 555 | |
| 556 | # Run updateApi for a single module, ex. appcompat-resources in group appcompat. |
| 557 | ./gradlew :appcompat:appcompat-resources:updateApi |
| 558 | ``` |
| 559 | |
| 560 | If you change the public APIs without updating the API file, your module will |
| 561 | still build **but** your CL will fail Treehugger presubmit checks. |
| 562 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 563 | NOTE The `updateApi` task does not generate versioned API files (e.g. |
| 564 | `1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task |
| 565 | will always generate `current.txt` API files. |
| 566 | |
alanv | a5fd21b | 2021-08-20 10:26:46 -0700 | [diff] [blame] | 567 | #### What are all these files in `api/`? {#updating-public-apis-glossary} |
| 568 | |
| 569 | Historical API surfaces are tracked for compatibility and docs generation |
| 570 | purposes. For each version -- including `current` to represent the tip-of-tree |
| 571 | version -- we record three different types of API surfaces. |
| 572 | |
| 573 | * `<version>.txt`: Public API surface, tracked for compatibility |
| 574 | * `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for |
| 575 | compatibility where necessary (see |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 576 | [Restricted APIs](/docs/api_guidelines/index.md#restricted-api)) |
alanv | a5fd21b | 2021-08-20 10:26:46 -0700 | [diff] [blame] | 577 | * `public_plus_experimental_<version>.txt`: Public API surface plus |
| 578 | `@RequiresOptIn` experimental API surfaces used for documentation (see |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 579 | [Experimental APIs](/docs/api_guidelines/index.md#experimental-api)) |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 580 | and API review |
alanv | a5fd21b | 2021-08-20 10:26:46 -0700 | [diff] [blame] | 581 | |
AndroidX Core Team | f2f418d | 2024-07-24 11:02:09 -0700 | [diff] [blame] | 582 | NOTE: Experimental API tracking for KLib is enabled by default for KMP projects |
| 583 | via parallel `updateAbi` and `checkAbi` tasks. If you have a problem with these |
| 584 | tools, |
| 585 | [please file an issue](https://issuetracker.google.com/issues/new?component=1102332&template=1780493). |
| 586 | As a workaround, you may opt-out by setting |
| 587 | `enableBinaryCompatibilityValidator = false` under |
| 588 | `AndroidxMultiplatformExtension` in your library's `build.gradle` file. |
| 589 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 590 | ### Release notes & the `Relnote:` tag {#relnote} |
| 591 | |
| 592 | Prior to releasing, release notes are pre-populated using a script and placed |
| 593 | into a Google Doc. The Google Doc is manually double checked by library owners |
| 594 | before the release goes live. To auto-populate your release notes, you can use |
| 595 | the semi-optional commit tag `Relnote:` in your commit, which will automatically |
| 596 | include that message the commit in the pre-populated release notes. |
| 597 | |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 598 | The presence of a `Relnote:` tag is required for API changes in `androidx-main`. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 599 | |
| 600 | #### How to use it? |
| 601 | |
| 602 | One-line release note: |
| 603 | |
| 604 | ``` {.good} |
| 605 | Relnote: Fixed a critical bug |
| 606 | ``` |
| 607 | |
| 608 | ``` {.good} |
| 609 | Relnote: "Fixed a critical bug" |
| 610 | ``` |
| 611 | |
| 612 | ``` {.good} |
| 613 | Relnote: Added the following string function: `myFoo(\"bar\")` |
| 614 | ``` |
| 615 | |
| 616 | Multi-line release note: |
| 617 | |
| 618 | Note: If the following lines do not contain an indent, you may hit b/165570183. |
| 619 | |
| 620 | ``` {.good} |
| 621 | Relnote: "We're launching this awesome new feature! It solves a whole list of |
| 622 | problems that require a lot of explaining! " |
| 623 | ``` |
| 624 | |
| 625 | ``` {.good} |
| 626 | Relnote: """Added the following string function: `myFoo("bar")` |
| 627 | It will fix cases where you have to call `myFoo("baz").myBar("bar")` |
| 628 | """ |
| 629 | ``` |
| 630 | |
| 631 | Opt out of the Relnote tag: |
| 632 | |
| 633 | ``` {.good} |
| 634 | Relnote: N/A |
| 635 | ``` |
| 636 | |
| 637 | ``` {.good} |
| 638 | Relnote: NA |
| 639 | ``` |
| 640 | |
| 641 | NOT VALID: |
| 642 | |
| 643 | ``` {.bad} |
| 644 | Relnote: This is an INVALID multi-line release note. Our current scripts won't |
| 645 | include anything beyond the first line. The script has no way of knowing when |
| 646 | the release note actually stops. |
| 647 | ``` |
| 648 | |
| 649 | ``` {.bad} |
| 650 | Relnote: This is an INVALID multi-line release note. "Quotes" need to be |
| 651 | escaped in order for them to be parsed properly. |
| 652 | ``` |
| 653 | |
| 654 | ### Common build errors |
| 655 | |
| 656 | #### Diagnosing build failures |
| 657 | |
| 658 | If you've encountered a build failure and you're not sure what is triggering it, |
| 659 | then please run |
| 660 | `./development/diagnose-build-failure/diagnose-build-failure.sh`. |
| 661 | |
| 662 | This script can categorize your build failure into one of the following |
| 663 | categories: |
| 664 | |
| 665 | * The Gradle Daemon is saving state in memory and triggering a failure |
| 666 | * Your source files have been changed and/or incompatible git commits have |
| 667 | been checked out |
| 668 | * Some file in the out/ dir is triggering an error |
| 669 | * If this happens, diagnose-build-failure.sh should also identify which |
| 670 | file(s) specifically |
| 671 | * The build is nondeterministic and/or affected by timestamps |
| 672 | * The build via gradlew actually passes and this build failure is specific to |
| 673 | Android Studio |
| 674 | |
| 675 | Some more-specific build failures are listed below in this page. |
| 676 | |
| 677 | #### Out-of-date platform prebuilts |
| 678 | |
| 679 | Like a normal Android library developed in Android Studio, libraries within |
| 680 | `androidx` are built against prebuilts of the platform SDK. These are checked in |
| 681 | to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory. |
| 682 | |
| 683 | If you are developing against pre-release platform APIs in the internal |
| 684 | `androidx-platform-dev` branch, you may need to update these prebuilts to obtain |
| 685 | the latest API changes. |
| 686 | |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 687 | #### Missing external dependency |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 688 | |
AndroidX Core Team | 8dcb0d1 | 2023-03-02 11:18:52 -0800 | [diff] [blame] | 689 | If Gradle cannot resolve a dependency listed in your `build.gradle`: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 690 | |
AndroidX Core Team | 8dcb0d1 | 2023-03-02 11:18:52 -0800 | [diff] [blame] | 691 | * You will probably want to import the missing artifact via |
| 692 | [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md) |
| 693 | |
| 694 | * We store artifacts in the prebuilts repositories under |
| 695 | `prebuilts/androidx` to facilitate reproducible builds even if remote |
| 696 | artifacts are changed. |
| 697 | |
| 698 | * You may need to [establish trust for](#dependency-verification) the new |
| 699 | artifact |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 700 | |
AndroidX Core Team | bae5256 | 2022-07-06 13:41:40 -0700 | [diff] [blame] | 701 | ##### Importing dependencies in `libs.versions.toml` |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 702 | |
| 703 | Libraries typically reference dependencies using constants defined in |
AndroidX Core Team | bae5256 | 2022-07-06 13:41:40 -0700 | [diff] [blame] | 704 | [`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml). |
| 705 | Update this file to include a constant for the version of the library that you |
| 706 | want to depend on. You will reference this constant in your library's |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 707 | `build.gradle` dependencies. |
| 708 | |
AndroidX Core Team | bae5256 | 2022-07-06 13:41:40 -0700 | [diff] [blame] | 709 | **After** you update the `libs.versions.toml` file with new dependencies, you |
| 710 | can download them by running: |
| 711 | |
| 712 | ```shell |
| 713 | cd frameworks/support &&\ |
| 714 | development/importMaven/importMaven.sh import-toml |
| 715 | ``` |
| 716 | |
| 717 | This command will resolve everything declared in the `libs.versions.toml` file |
| 718 | and download missing artifacts into `prebuilts/androidx/external` or |
| 719 | `prebuilts/androidx/internal`. |
| 720 | |
| 721 | Make sure to upload these changes before or concurrently (ex. in the same Gerrit |
| 722 | topic) with the dependent library code. |
| 723 | |
| 724 | ##### Downloading a dependency without changing `libs.versions.toml` |
| 725 | |
| 726 | You can also download a dependency without changing `libs.versions.toml` file by |
| 727 | directly invoking: |
| 728 | |
| 729 | ```shell |
| 730 | cd frameworks/support &&\ |
| 731 | ./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion |
| 732 | ``` |
| 733 | |
| 734 | ##### Missing konan dependencies |
| 735 | |
| 736 | Kotlin Multiplatform projects need prebuilts to compile native code, which are |
| 737 | located under `prebuilts/androidx/konan`. **After** you update the kotlin |
| 738 | version of AndroidX, you should also download necessary prebuilts via: |
| 739 | |
| 740 | ```shell |
| 741 | cd frameworks/support &&\ |
| 742 | development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version> |
| 743 | ``` |
| 744 | |
| 745 | Please remember to commit changes in the `prebuilts/androidx/konan` repository. |
| 746 | |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 747 | #### Dependency verification |
| 748 | |
AndroidX Core Team | 8dcb0d1 | 2023-03-02 11:18:52 -0800 | [diff] [blame] | 749 | If you import a new dependency that is either unsigned or is signed with a new, |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 750 | unrecognized key, then you will need to add new dependency verification metadata |
AndroidX Core Team | 8dcb0d1 | 2023-03-02 11:18:52 -0800 | [diff] [blame] | 751 | to indicate to Gradle that this new dependency is trusted. See the instructions |
| 752 | [here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md) |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 753 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 754 | #### Updating an existing dependency |
| 755 | |
| 756 | If an older version of a dependency prebuilt was already checked in, please |
| 757 | manually remove it within the same CL that adds the new prebuilt. You will also |
| 758 | need to update `Dependencies.kt` to reflect the version change. |
| 759 | |
| 760 | #### My gradle build fails with "Cannot invoke method getURLs() on null object" |
| 761 | |
| 762 | You're using Java 9's javac, possibly because you ran envsetup.sh from the |
| 763 | platform build or specified Java 9 as the global default Java compiler. For the |
| 764 | former, you can simply open a new shell and avoid running envsetup.sh. For the |
| 765 | latter, we recommend you set Java 8 as the default compiler using sudo |
| 766 | update-java-alternatives; however, if you must use Java 9 as the default then |
| 767 | you may alternatively set JAVA_HOME to the location of the Java 8 SDK. |
| 768 | |
| 769 | #### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes. |
| 770 | |
| 771 | You probably need to update the prebuilt SDK used by the gradle build. If you |
| 772 | are referencing new framework APIs, you will need to wait for the framework |
| 773 | changes to land in an SDK build (or build it yourself) and then land in both |
| 774 | prebuilts/fullsdk and prebuilts/sdk. See |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 775 | [Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk) |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 776 | for more information. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 777 | |
| 778 | #### How do I handle refactoring a framework API referenced from a library? |
| 779 | |
| 780 | Because AndroidX must compile against both the current framework and the latest |
| 781 | SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you |
AndroidX Core Team | 5ad2f7f | 2023-01-20 12:26:18 -0500 | [diff] [blame] | 782 | will need to refactor in stages: |
| 783 | |
| 784 | 1. Remove references to the target APIs from AndroidX |
| 785 | 2. Perform the refactoring in the framework |
| 786 | 3. Update the framework prebuilt SDK to incorporate changes in (2) |
| 787 | 4. Add references to the refactored APIs in AndroidX |
| 788 | 5. Update AndroidX prebuilts to incorporate changes in (4) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 789 | |
| 790 | ## Testing {#testing} |
| 791 | |
| 792 | AndroidX libraries are expected to include unit or integration test coverage for |
| 793 | 100% of their public API surface. Additionally, all CLs must include a `Test:` |
| 794 | stanza indicating which tests were used to verify correctness. Any CLs |
| 795 | implementing bug fixes are expected to include new regression tests specific to |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 796 | the issue being fixed. |
| 797 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 798 | ### Running tests {#run-tests} |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 799 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 800 | Generally, tests in the AndroidX repository should be run through the Android |
| 801 | Studio UI. You can also run tests from the command line or via remote devices on |
| 802 | FTL, see |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 803 | [Running unit and integration tests](/docs/testing.md#running) |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 804 | for details. |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 805 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 806 | #### Single test class or method |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 807 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 808 | 1. Open the desired test file in Android Studio |
| 809 | 2. Right-click on a test class or `@Test` method name and select `Run <name>` |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 810 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 811 | #### Full test package |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 812 | |
AndroidX Core Team | bf2f7f3 | 2023-04-24 12:58:05 -0700 | [diff] [blame] | 813 | 1. In the `Project` side panel, open the desired module |
| 814 | 2. Find the package directory with the tests |
| 815 | 3. Right-click on the directory and select `Run <package>` |
| 816 | |
| 817 | ### Running sample apps {#run-samples} |
AndroidX Core Team | 21ccf65 | 2022-04-01 14:53:07 +0000 | [diff] [blame] | 818 | |
| 819 | The AndroidX repository has a set of Android applications that exercise AndroidX |
| 820 | code. These applications can be useful when you want to debug a real running |
| 821 | application, or reproduce a problem interactively, before writing test code. |
| 822 | |
| 823 | These applications are named either `<libraryname>-integration-tests-testapp`, |
| 824 | or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You |
| 825 | can run them by clicking `Run > Run ...` and choosing the desired application. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 826 | |
Ian Baker | 186108e | 2023-11-20 06:54:36 -0800 | [diff] [blame] | 827 | See the [Testing](/docs/testing.md) page for more resources on |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 828 | writing, running, and monitoring tests. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 829 | |
| 830 | ### AVD Manager |
| 831 | |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 832 | The Android Studio instance started by `./studiow` uses a custom SDK directory, |
| 833 | which means any virtual devices created by a "standard" non-AndroidX instance of |
AndroidX Core Team | e1288a7 | 2021-09-03 12:30:13 -0700 | [diff] [blame] | 834 | Android Studio will be *visible* from the `./studiow` instance but will be |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 835 | unable to locate the SDK artifacts -- they will display a `Download` button. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 836 | |
| 837 | You can either use the `Download` button to download an extra copy of the SDK |
AndroidX Core Team | e1288a7 | 2021-09-03 12:30:13 -0700 | [diff] [blame] | 838 | artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK |
AndroidX Core Team | ee1457a | 2021-02-25 16:13:10 +0000 | [diff] [blame] | 839 | directory to expose your existing artifacts to the `./studiow` instance: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 840 | |
| 841 | ```shell |
| 842 | # Using the default MacOS Android SDK directory... |
| 843 | ln -s /Users/$(whoami)/Library/Android/sdk/system-images \ |
| 844 | ../../prebuilts/fullsdk-darwin/system-images |
| 845 | ``` |
| 846 | |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 847 | ## Library snapshots {#snapshots} |
| 848 | |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 849 | ### Quick how-to |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 850 | |
| 851 | Add the following snippet to your build.gradle file, replacing `buildId` with a |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 852 | snapshot build ID. |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 853 | |
| 854 | ```groovy {highlight=context:[buildId]} |
| 855 | allprojects { |
| 856 | repositories { |
| 857 | google() |
| 858 | jcenter() |
| 859 | maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' } |
| 860 | } |
| 861 | } |
| 862 | ``` |
| 863 | |
AndroidX Core Team | ee9c1aa | 2021-04-06 17:29:05 +0000 | [diff] [blame] | 864 | You must define dependencies on artifacts using the `SNAPSHOT` version suffix, |
| 865 | for example: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 866 | |
| 867 | ```groovy {highlight=context:SNAPSHOT} |
| 868 | dependencies { |
| 869 | implementation "androidx.core:core:1.2.0-SNAPSHOT" |
| 870 | } |
| 871 | ``` |
| 872 | |
| 873 | ### Where to find snapshots |
| 874 | |
| 875 | If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you |
| 876 | can find them on either our public-facing build server: |
| 877 | |
| 878 | `https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest` |
| 879 | |
| 880 | or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site: |
| 881 | |
AndroidX Core Team | 6e4288b | 2022-07-13 13:53:43 -0700 | [diff] [blame] | 882 | `https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific |
| 883 | build ID |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 884 | |
AndroidX Core Team | 6e4288b | 2022-07-13 13:53:43 -0700 | [diff] [blame] | 885 | `https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 886 | |
| 887 | ### Obtaining a build ID |
| 888 | |
| 889 | To browse build IDs, you can visit either |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 890 | [androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 891 | on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the |
| 892 | androidx.dev site. |
| 893 | |
| 894 | Note that if you are using androidx.dev, you may substitute `latest` for a build |
| 895 | ID to use the last known good build. |
| 896 | |
| 897 | To manually find the last known good `build-id`, you have several options. |
| 898 | |
| 899 | #### Snapshots on androidx.dev |
| 900 | |
| 901 | [Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists |
| 902 | usable builds. |
| 903 | |
| 904 | #### Programmatically via `jq` |
| 905 | |
| 906 | Install `jq`: |
| 907 | |
| 908 | ```shell |
| 909 | sudo apt-get install jq |
| 910 | ``` |
| 911 | |
| 912 | ```shell |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 913 | ID=`curl -s "https://ci.android.com/builds/branches/aosp-androidx-main/status.json" | jq ".targets[] | select(.ID==\"aosp-androidx-main.androidx_snapshot\") | .last_known_good_build"` \ |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 914 | && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/ |
| 915 | ``` |
| 916 | |
| 917 | #### Android build server |
| 918 | |
| 919 | Go to |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame] | 920 | [androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 921 | on ci.android.com. |
| 922 | |
| 923 | For `androidx-snapshot` target, wait for the green "last known good build" |
| 924 | button to load and then click it to follow it to the build artifact URL. |
| 925 | |
| 926 | ### Using in a Gradle build |
| 927 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 928 | To make these artifacts visible to Gradle, you need to add it as a repository: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 929 | |
| 930 | ```groovy |
| 931 | allprojects { |
| 932 | repositories { |
| 933 | google() |
| 934 | maven { |
| 935 | // For all Jetpack libraries (including Compose) |
| 936 | url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository' |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | ``` |
| 941 | |
| 942 | Note that the above requires you to know the `build-id` of the snapshots you |
| 943 | want. |
| 944 | |
| 945 | #### Specifying dependencies |
| 946 | |
| 947 | All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So |
| 948 | to use a snapshot artifact, the version in your `build.gradle` will need to be |
| 949 | updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT` |
| 950 | |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 951 | For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 952 | following to your `build.gradle`: |
| 953 | |
| 954 | ``` |
| 955 | dependencies { |
| 956 | ... |
| 957 | implementation("androidx.core:core:1.2.0-SNAPSHOT") |
| 958 | ... |
| 959 | } |
| 960 | ``` |
| 961 | |
| 962 | ## FAQ {#faq} |
| 963 | |
| 964 | ### How do I test my change in a separate Android Studio project? {#faq-test-change-studio} |
| 965 | |
| 966 | If you're working on a new feature or bug fix in AndroidX, you may want to test |
| 967 | your changes against another project to verify that the change makes sense in a |
| 968 | real-world context or that a bug's specific repro case has been fixed. |
| 969 | |
| 970 | If you need to be absolutely sure that your test will exactly emulate the |
| 971 | developer's experience, you can repeatedly build the AndroidX archive and |
| 972 | rebuild your application. In this case, you will need to create a local build of |
| 973 | AndroidX's local Maven repository artifact and install it in your Android SDK |
| 974 | path. |
| 975 | |
| 976 | First, use the `createArchive` Gradle task to generate the local Maven |
| 977 | repository artifact: |
| 978 | |
| 979 | ```shell |
AndroidX Core Team | cb7de29 | 2024-08-07 14:25:42 -0700 | [diff] [blame] | 980 | # Creates <path-to-checkout>/out/repository/ |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 981 | ./gradlew createArchive |
| 982 | ``` |
| 983 | |
AndroidX Core Team | d719592 | 2023-10-02 08:43:33 -0700 | [diff] [blame] | 984 | Using your alternate (non-AndroidX) version of Android Studio open the project's |
| 985 | `settings.gradle.kts` and add the following within |
| 986 | `dependencyResolutionManagement` to make your project look for binaries in the |
| 987 | newly built repository: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 988 | |
AndroidX Core Team | d719592 | 2023-10-02 08:43:33 -0700 | [diff] [blame] | 989 | ```kotlin |
| 990 | dependencyResolutionManagement { |
| 991 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 992 | repositories { |
AndroidX Core Team | d719592 | 2023-10-02 08:43:33 -0700 | [diff] [blame] | 993 | google() |
| 994 | mavenCentral() |
| 995 | // Add this |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 996 | maven { |
AndroidX Core Team | cb7de29 | 2024-08-07 14:25:42 -0700 | [diff] [blame] | 997 | setUrl("<path-to-sdk>/out/repository/") |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | ``` |
| 1002 | |
| 1003 | NOTE Gradle resolves dependencies in the order that the repositories are defined |
| 1004 | (if 2 repositories can resolve the same dependency, the first listed will do so |
| 1005 | and the second will not). Therefore, if the library you are testing has the same |
| 1006 | group, artifact, and version as one already published, you will want to list |
| 1007 | your custom maven repo first. |
| 1008 | |
| 1009 | Finally, in the dependencies section of your standalone project's `build.gradle` |
| 1010 | file, add or update the `implementation` entries to reflect the AndroidX modules |
| 1011 | that you would like to test. Example: |
| 1012 | |
| 1013 | ``` |
| 1014 | dependencies { |
| 1015 | ... |
AndroidX Core Team | d719592 | 2023-10-02 08:43:33 -0700 | [diff] [blame] | 1016 | implementation "androidx.appcompat:appcompat:1.0.0-alpha02" |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 1017 | } |
| 1018 | ``` |
| 1019 | |
| 1020 | If you are testing your changes in the Android Platform code, you can replace |
| 1021 | the module you are testing |
| 1022 | `YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own |
| 1023 | module. We recommend only replacing the module you are modifying instead of the |
| 1024 | full m2repository to avoid version issues of other modules. You can either take |
| 1025 | the unzipped directory from |
| 1026 | `<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from |
AndroidX Core Team | cb7de29 | 2024-08-07 14:25:42 -0700 | [diff] [blame] | 1027 | `<path-to-checkout>/out/repository/` after building `androidx`. Here is an |
| 1028 | example of replacing the RecyclerView module: |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 1029 | |
| 1030 | ```shell |
| 1031 | $TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07; |
| 1032 | rm -rf $TARGET; |
| 1033 | cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET |
| 1034 | ``` |
| 1035 | |
| 1036 | Make sure the library versions are the same before and after replacement. Then |
| 1037 | you can build the Android platform code with the new `androidx` code. |
AndroidX Core Team | 4cc85fa | 2021-11-23 15:58:34 +0000 | [diff] [blame] | 1038 | |
AndroidX Core Team | f74ae23 | 2022-04-25 11:17:51 -0400 | [diff] [blame] | 1039 | ### How do I add content to a library's Overview reference doc page? |
| 1040 | |
| 1041 | Put content in a markdown file that ends with `-documentation.md` in the |
| 1042 | directory that corresponds to the Overview page that you'd like to document. |
| 1043 | |
| 1044 | For example, the `androidx.compose.runtime` |
| 1045 | [Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary) |
| 1046 | includes content from |
| 1047 | [compose-runtime-documentation.md](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/compose-runtime-documentation.md). |
AndroidX Core Team | 5fa6198 | 2023-01-13 10:43:41 -0500 | [diff] [blame] | 1048 | |
| 1049 | ### How do I enable MultiDex for my library? |
| 1050 | |
AndroidX Core Team | 5c7f3df | 2024-06-24 12:06:54 -0700 | [diff] [blame] | 1051 | It is enabled automatically as androidx minSdkVersion is API >=21. |