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