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