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