blob: 88ae7f5c3ce56db076a47b96d2e3915f72ad0662 [file] [log] [blame] [view]
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001# Getting started
2
3[TOC]
4
5This page describes how to set up your workstation to check out source code,
6make simple changes in Android Studio, and upload commits to Gerrit for review.
7
8This page does **not** cover best practices for the content of changes. Please
Ian Baker186108e2023-11-20 06:54:36 -08009see [Life of a Jetpack Feature](/docs/loaf.md) for details on
AndroidX Core Team76f65452024-01-02 11:39:57 -080010creating and releasing a library or
Ian Baker186108e2023-11-20 06:54:36 -080011[API Guidelines](/docs/api_guidelines/index.md) for best
AndroidX Core Team76f65452024-01-02 11:39:57 -080012practices regarding library development.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000013
14## Workstation setup {#setup}
15
AndroidX Core Teamcc1e9b12022-06-27 13:10:24 -070016This section will help you install the `repo` tool, which is used for Git branch
17and commit management. If you want to learn more about `repo`, see the
18[Repo Command Reference](https://source.android.com/setup/develop/repo).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000019
AndroidX Core Team95040f72024-10-10 14:31:18 -070020NOTE The `repo` tool uses Git submodules under the hood, and it is possible to
21skip using the tool in favor of using submodules directly. If you prefer to use
22submodules, look for notes anywhere that `repo` is mentioned in this document.
23Submodule users can skip Workstation setup.
24
AndroidX Core Team2e416b22020-12-03 22:58:07 +000025### Linux and MacOS {#setup-linux-mac}
26
27First, download `repo` using `curl`.
28
29```shell
30test -d ~/bin || mkdir ~/bin
31curl https://storage.googleapis.com/git-repo-downloads/repo \
32 > ~/bin/repo && chmod 700 ~/bin/repo
33```
34
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080035Then, modify `~/.zshrc` (or `~/.bash_profile` if using `bash`) to ensure you can
AndroidX Core Team21ccf652022-04-01 14:53:07 +000036find local binaries from the command line. We assume you're using `zsh`, but the
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080037following should work with `bash` as well.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000038
39```shell
40export PATH=~/bin:$PATH
41```
42
AndroidX Core Team693e3f82024-05-17 05:25:53 -070043> NOTE: When using quotes (`"~/bin"`), `~` does not expand and the path is
44> invalid. (Possibly `bash` only?)
45
AndroidX Core Team68274512022-04-28 13:10:15 -070046Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using
47`bash`) aliasing the `repo` command to run with `python3`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +000048
49```shell
50# Force repo to run with Python3
51function repo() {
AndroidX Core Team21ccf652022-04-01 14:53:07 +000052 command python3 ~/bin/repo $@
AndroidX Core Team2e416b22020-12-03 22:58:07 +000053}
54```
55
AndroidX Core Team68274512022-04-28 13:10:15 -070056Finally, you will need to either start a new terminal session or run `source
57~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes.
58
59> NOTE: If you encounter the following warning about Python 2 being no longer
60> supported, you will need to install Python 3 from the
61> [official website](https://www.python.org).
62>
63> ```shell {.bad}
64> repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
65> ```
66
67> NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error:
68>
69> ```shell {.bad}
70> Downloading Repo source from https://gerrit.googlesource.com/git-repo
71> fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
72> fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)
73> ```
74>
AndroidX Core Teamf95fde72024-05-07 11:03:03 -070075> Run the `Install Certificates.command` in the Python folder of Application
76> (e.g. `/Applications/Python\ 3.11/Install\ Certificates.command`). For more
77> information about SSL/TLS certificate validation, you can read the "Important
78> Information" displayed during Python installation.
AndroidX Core Team21ccf652022-04-01 14:53:07 +000079
AndroidX Core Team2e416b22020-12-03 22:58:07 +000080### Windows {#setup-win}
81
82Sorry, Windows is not a supported platform for AndroidX development.
83
84## Set up access control {#access}
85
86### Authenticate to AOSP Gerrit {#access-gerrit}
87
88Before you can upload changes, you will need to associate your Google
89credentials with the AOSP Gerrit code review system by signing in to
90[android-review.googlesource.com](https://android-review.googlesource.com) at
91least once using the account you will use to submit patches.
92
93Next, you will need to
AndroidX Core Team1770ed72024-08-12 10:18:54 -070094[set up authentication](https://android.googlesource.com/new-password).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000095This will give you a shell command to update your local Git cookies, which will
96allow you to upload changes.
97
98Finally, you will need to accept the
99[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
100
101## Check out the source {#source}
102
AndroidX Core Teamcb2bed82025-01-07 09:36:21 -0800103Like ChromeOS, Chromium, and the Android OS, we develop in the open as much as
104possible. All feature development occurs in the public
105[`androidx-main`](https://android.googlesource.com/platform/superproject/+/refs/heads/androidx-main)
106`repo` branch of the Android Open Source Project, with majority of the code in
107the
108[`frameworks/support` git repository](https://android.googlesource.com/platform/frameworks/support/+/androidx-main).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000109
AndroidX Core Team95040f72024-10-10 14:31:18 -0700110As of 2024/10/10, you will need about XXX GB for a clean checkout or YYY GB for
111a fully-built checkout.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000112
113### Synchronize the branch {#source-checkout}
114
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000115Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000116
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500117#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000118
119All development should occur in this branch unless otherwise specified by the
120AndroidX Core team.
121
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000122The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000123
124```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000125mkdir androidx-main && cd androidx-main
alanv7ae48942022-09-27 13:53:32 -0700126repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000127 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team95040f72024-10-10 14:31:18 -0700128repo sync -c -j32
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000129```
130
131NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
132you may need to install Python3 and boot strap the SSL certificates in the
133included version of pip. You can execute `Install Certificates.command` under
134`/Applications/Python 3.6/` to do so.
135
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400136NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
137failed with exit status -6` with cause `md_enable: algorithm 10 not available`
138you may need to install a build of `gpg` that supports SHA512, such as the
139latest version available from [Homebrew](https://brew.sh/) using `brew install
140gpg`.
141
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000142### Increase Git rename limit {#source-config}
143
144To ensure `git` can detect diffs and renames across significant changes (namely,
145the `androidx.*` package rename), we recommend that you set the following `git
146config` properties:
147
148```shell
149git config --global merge.renameLimit 999999
150git config --global diff.renameLimit 999999
151```
152
alanv207674d2022-06-14 11:20:52 -0700153### Set up Git file exclusions {#source-exclude}
154
155Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
156avoid accidentally checking in local metadata files:
157
158```shell
159echo .DS_Store>>~/.gitignore
160git config --global core.excludesFile '~/.gitignore'
161```
162
163### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400164
165The
166[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
167contains a history of the matching exact commits of each git repository over
168time, and it can be
169[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
170
alanve9101e42022-01-28 12:05:11 -0800171### Troubleshooting
172
173> NOTE: If the repo manifest changes -- for example when we update the version
174> of `platform-tools` by pointing it to a different git project -- you may see
175> the following error during`repo sync`:
176>
177> ```shell
178> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
179> ...
180> error: Unable to fully sync the tree.
181> error: Downloading network changes failed.
182> ```
183>
184> This indicates that Studio or some other process has made changes in the git
185> project that has been replaced or removed. You can force `repo sync` to
186> discard these changes and check out the correct git project by adding the
187> `--force-sync` argument:
188>
189> ```shell
190> repo sync -j32 --force-sync
191> ```
192
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000193## Explore source code from a browser {#code-search}
194
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000195`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000196[code search](https://cs.android.com/androidx/platform/frameworks/support) that
197allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000198URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000199
AndroidX Core Team110f54d2022-10-24 08:35:31 -0700200### Custom search engine for `androidx-main` {#custom-search-engine}
201
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000202We recommend setting up a custom search engine in Chrome as a faster (and
203publicly-accessible) alternative to `cs/`.
204
AndroidX Core Team2e416b22020-12-03 22:58:07 +00002051. Open `chrome://settings/searchEngines`
2061. Click the `Add` button
2071. Enter a name for your search engine, ex. "AndroidX Code Search"
2081. Enter a keyword, ex. "csa"
2091. Enter the following URL:
210 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
2111. Click the `Add` button
212
213Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
214query to search for, e.g. `AppCompatButton file:appcompat`, and press the
215`Enter` key to get to the search result page.
216
217## Develop in Android Studio {#studio}
218
219Library development uses a curated version of Android Studio to ensure
220compatibility between various components of the development workflow.
221
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000222From the `frameworks/support` directory, you can use `./studiow m` (short for
223`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400224correct version of Studio to work on the `main` set of androidx projects
225(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000226[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
227also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400228projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000229
230Next, open the `framework/support` project root from your checkout. If Studio
231asks you which SDK you would like to use, select `Use project SDK`. Importing
232projects may take a while, but once that finishes you can use Studio as you
233normally would for application or library development -- right-click on a test
234or sample to run or debug it, search through classes, and so on.
235
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000236> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
237> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
238> opening `File > Project Structure > Platform Settings > SDKs` and manually
239> setting the Android SDK home path to
240> `<project-root>/prebuilts/fullsdk-<platform>`.
241
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500242### Troubleshooting {#studio-troubleshooting}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000243
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500244* If you've updated to macOS Ventura and receive a "xcrun: error: invalid
245 active developer path" message when running Studio, reinstall Xcode using
246 `xcode-select --install`. If that does not work, you will need to download
247 Xcode.
248* If you get a “Unregistered VCS root detected” message, click “Add root” to
249 enable the Git/VCS integration for Android Studio.
250* If you see any errors (red underlines), click Gradle's elephant button in
251 the toolbar (or `File > Sync Project with Gradle Files`) and they should
252 resolve once the build completes.
253* If you run `./studiow` with a new project set but you're still seeing the
254 old project set in `Project`, use `File > Sync Project with Gradle Files` to
255 force a re-sync.
256* If Android Studio's UI looks scaled up, ex. twice the size it should be, you
257 may need to add the following line to your `studio64.vmoptions` file using
258 `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false`
259* If you don't see a specific Gradle task listed in Studio's Gradle pane,
260 check the following:
261 * Studio might be running a different project subset than the one
262 intended. For example, `./studiow main` only loads the `main` set of
263 androidx projects; run `./studiow compose` to load the tasks specific to
264 Compose.
265 * Gradle tasks aren't being loaded. Under Studio's settings =>
266 Experimental, make sure that "Do not build Gradle task list during
267 Gradle sync" is unchecked. Note that unchecking this can reduce Studio's
268 performance.
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700269
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000270If in the future you encounter unexpected errors in Studio and you want to check
271for the possibility it is due to some incorrect settings or other generated
272files, you can run `./studiow --clean main <project subset>` or `./studiow
273--reinstall <project subset>` to clean generated files or reinstall Studio.
274
alanv07cfb5e2022-10-12 11:14:08 -0700275### Enabling Compose `@Preview` annotation previews
AndroidX Core Team6173c652022-05-19 20:43:28 +0000276
alanv07cfb5e2022-10-12 11:14:08 -0700277Add the following dependencies to your project's `build.gradle`:
AndroidX Core Team6173c652022-05-19 20:43:28 +0000278
279```groovy
280dependencies {
281 implementation(project(":compose:ui:ui-tooling-preview"))
282 debugImplementation(project(":compose:ui:ui-tooling"))
283}
284```
285
alanv07cfb5e2022-10-12 11:14:08 -0700286Then,
AndroidX Core Team6173c652022-05-19 20:43:28 +0000287[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
288
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000289## Making changes {#changes}
290
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000291Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000292CL-specific working branches. Use `repo` to create, upload, and abandon local
293branches. Use `git` to manage changes within a local branch.
294
295```shell
296cd path/to/checkout/frameworks/support/
297repo start my_branch_name .
298# make necessary code changes
299# use git to commit changes
300repo upload --cbr -t .
301```
302
303The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000304`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
305can refer to the
306[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
307for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000308
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000309If you see the following prompt, choose `always`:
310
311```
312Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
313```
314
315If the upload succeeds, you'll see an output like:
316
317```
318remote:
319remote: New Changes:
320remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
321remote:
322```
323
324To edit your change, use `git commit --amend`, and re-upload.
325
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000326NOTE If you encounter issues with `repo upload`, consider running upload with
327trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
328logs can be helpful for reporting issues to the team that manages our git
329servers.
330
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000331NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
332skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
333hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
334to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
335
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700336### Fixing Kotlin code style errors
337
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700338`repo upload` automatically runs `ktfmt`, which will cause the upload to fail if
339your code has style errors, which it reports on the command line like so:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700340
341```
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700342[FAILED] ktfmt_hook
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700343 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
344```
345
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700346To find and fix these errors, you can run ktfmt locally, either in a console
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700347window or in the Terminal tool in Android Studio. Running in the Terminal tool
348is preferable because it will surface links to your source files/lines so you
349can easily navigate to the code to fix any problems.
350
351First, to run the tool and see all of the errors, run:
352
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700353`./gradlew module:submodule:ktCheck`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700354
355where module/submodule are the names used to refer to the module you want to
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700356check, such as `navigation:navigation-common`. You can also run ktfmt on the
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700357entire project, but that takes longer as it is checking all active modules in
358your project.
359
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700360Many of the errors that ktfmt finds can be automatically fixed by running
361ktFormat:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700362
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700363`./gradlew module:submodule:ktFormat`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700364
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700365ktFormat will report any remaining errors, but you can also run `ktCheck` again
366at any time to see an updated list of the remaining errors.
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700367
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000368## Building {#building}
369
370### Modules and Maven artifacts {#modules-and-maven-artifacts}
371
372To build a specific module, use the module's `assemble` Gradle task. For
373example, if you are working on `core` module use:
374
375```shell
376./gradlew core:core:assemble
377```
378
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000379To make warnings fail your build (same as presubmit), use the `--strict` flag,
380which our gradlew expands into a few correctness-related flags including
AndroidX Core Team9d812cd2022-09-01 15:42:06 -0700381`-Pandroidx.validateNoUnrecognizedMessages`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000382
383```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000384./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000385```
386
AndroidX Core Team48bd93c2025-01-09 12:52:55 -0800387To generate a local Maven artifact for the specific module and place it in
388`out/repository`, use the `publish` Gradle task:
389
390```shell
391./gradlew core:core:publish
392```
393
394To build every module and generate the local Maven repository artifacts and
395place them in `out/repository`, use the `createArchive` Gradle task:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000396
397```shell
398./gradlew createArchive
399```
400
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000401To run the complete build task that our build servers use, use the corresponding
402shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000403
404```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000405./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000406```
407
408### Attaching a debugger to the build
409
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700410Gradle tasks, including building a module, may be run or debugged from within
411Android Studio. To start, you need to add the task as a run configuration: you
412can do this manually by adding the corresponding task by clicking on the run
413configuration dropdown, pressing
414[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
415and adding the corresponding task.
416
417You can also run the task through the IDE from the terminal, by using the
418[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
419feature - type in the task you want to run in the in-IDE terminal, and
420`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
421automatically add the configuration to the run configuration menu - you can then
422cancel the task.
423
424Once the task has been added to the run configuration menu, you can start
425debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000426
427Note that debugging will not be available until Gradle sync has completed.
428
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000429#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000430
431Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000432`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000433
AndroidX Core Team6173c652022-05-19 20:43:28 +00004341. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004351. Click the plus in the top left to create a new "Remote" configuration. Give
436 it a name and hit "Ok".
4371. Set breakpoints.
4381. Run your task with added flags: `./gradlew <your_task_here>
439 -Dorg.gradle.debug=true --no-daemon`
4401. Hit the "Debug" button to the right of the configuration dropdown to attach
441 to the process.
442
443#### Troubleshooting the debugger
444
445If you get a "Connection refused" error, it's likely because a gradle daemon is
446still running on the port specified in the config, and you can fix this by
447killing the running gradle daemons:
448
449```shell
450./gradlew --stop
451```
452
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000453NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000454[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
455
456#### Attaching to an annotation processor
457
458Annotation processors run as part of the build, to debug them is similar to
459debugging the build.
460
461For a Java project:
462
463```shell
464./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
465```
466
467For a Kotlin project:
468
469```shell
470./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"
471```
472
473### Optional: Enabling internal menu in IntelliJ/Studio
474
475To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
476Android Lint checks and Metalava, you can enable the
477[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
478which is typically used for plugin and IDE development.
479
480### Reference documentation {#docs}
481
482Our reference docs (Javadocs and KotlinDocs) are published to
483https://developer.android.com/reference/androidx/packages and may be built
484locally.
485
486NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
487run `./gradlew tasks`
488
AndroidX Core Team76f65452024-01-02 11:39:57 -0800489#### Generate docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700490
491To build API reference docs for both Java and Kotlin source code using Dackka,
492run the Gradle task:
493
494```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500495./gradlew docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700496```
497
498Location of generated refdocs:
499
500* docs-public (what is published to DAC):
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500501 `{androidx-main}/out/androidx/docs-public/build/docs`
502* docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700503
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700504The generated docs are plain HTML pages with links that do not work locally.
505These issues are fixed when the docs are published to DAC, but to preview a
506local version of the docs with functioning links and CSS, run:
507
508```
509python3 development/offlinifyDocs/offlinify_dackka_docs.py
510```
511
512You will need to have the `bs4` Python package installed. The CSS used is not
513the same as what will be used when the docs are published.
514
515By default, this command converts the tip-of-tree docs for all libraries. To see
516more options, run:
517
518```
519python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
520```
521
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000522#### Release docs
523
524To build API reference docs for published artifacts formatted for use on
525[d.android.com](http://d.android.com), run the Gradle command:
526
527```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500528./gradlew zipDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000529```
530
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500531This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This
532command builds docs based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000533`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
534the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000535`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000536colloquially refer to this two step process of (1) updating `docs-public` and
537(2) checking in a prebuilt artifact into the prebuilts directory as
Ian Baker186108e2023-11-20 06:54:36 -0800538[The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™).
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500539So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000540https://developer.android.com/reference/androidx/packages, both of these steps
541need to be completed.
542
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000543### Updating public APIs {#updating-public-apis}
544
545Public API tasks -- including tracking, linting, and verifying compatibility --
546are run under the following conditions based on the `androidx` configuration
547block, evaluated in order:
548
549* `runApiTasks=Yes` => yes
550* `runApiTasks=No` => no
551* `toolingProject=true` => no
552* `mavenVersion` or group version not set => no
553* Has an existing `api/` directory => yes
554* `publish=SNAPSHOT_AND_RELEASE` => yes
555* Otherwise, no
556
557If you make changes to tracked public APIs, you will need to acknowledge the
558changes by updating the `<component>/api/current.txt` and associated API files.
559This is handled automatically by the `updateApi` Gradle task:
560
561```shell
562# Run updateApi for all modules.
563./gradlew updateApi
564
565# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
566./gradlew :appcompat:appcompat-resources:updateApi
567```
568
569If you change the public APIs without updating the API file, your module will
570still build **but** your CL will fail Treehugger presubmit checks.
571
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500572NOTE The `updateApi` task does not generate versioned API files (e.g.
573`1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task
574will always generate `current.txt` API files.
575
alanva5fd21b2021-08-20 10:26:46 -0700576#### What are all these files in `api/`? {#updating-public-apis-glossary}
577
578Historical API surfaces are tracked for compatibility and docs generation
579purposes. For each version -- including `current` to represent the tip-of-tree
580version -- we record three different types of API surfaces.
581
582* `<version>.txt`: Public API surface, tracked for compatibility
583* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
584 compatibility where necessary (see
Ian Baker186108e2023-11-20 06:54:36 -0800585 [Restricted APIs](/docs/api_guidelines/index.md#restricted-api))
alanva5fd21b2021-08-20 10:26:46 -0700586* `public_plus_experimental_<version>.txt`: Public API surface plus
587 `@RequiresOptIn` experimental API surfaces used for documentation (see
Ian Baker186108e2023-11-20 06:54:36 -0800588 [Experimental APIs](/docs/api_guidelines/index.md#experimental-api))
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500589 and API review
alanva5fd21b2021-08-20 10:26:46 -0700590
AndroidX Core Teamf2f418d2024-07-24 11:02:09 -0700591NOTE: Experimental API tracking for KLib is enabled by default for KMP projects
592via parallel `updateAbi` and `checkAbi` tasks. If you have a problem with these
593tools,
594[please file an issue](https://issuetracker.google.com/issues/new?component=1102332&template=1780493).
595As a workaround, you may opt-out by setting
596`enableBinaryCompatibilityValidator = false` under
597`AndroidxMultiplatformExtension` in your library's `build.gradle` file.
598
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000599### Release notes & the `Relnote:` tag {#relnote}
600
601Prior to releasing, release notes are pre-populated using a script and placed
602into a Google Doc. The Google Doc is manually double checked by library owners
603before the release goes live. To auto-populate your release notes, you can use
604the semi-optional commit tag `Relnote:` in your commit, which will automatically
605include that message the commit in the pre-populated release notes.
606
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000607The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000608
609#### How to use it?
610
611One-line release note:
612
613``` {.good}
614Relnote: Fixed a critical bug
615```
616
617``` {.good}
618Relnote: "Fixed a critical bug"
619```
620
621``` {.good}
622Relnote: Added the following string function: `myFoo(\"bar\")`
623```
624
625Multi-line release note:
626
627Note: If the following lines do not contain an indent, you may hit b/165570183.
628
629``` {.good}
630Relnote: "We're launching this awesome new feature! It solves a whole list of
631 problems that require a lot of explaining! "
632```
633
634``` {.good}
635Relnote: """Added the following string function: `myFoo("bar")`
636 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
637 """
638```
639
640Opt out of the Relnote tag:
641
642``` {.good}
643Relnote: N/A
644```
645
646``` {.good}
647Relnote: NA
648```
649
650NOT VALID:
651
652``` {.bad}
653Relnote: This is an INVALID multi-line release note. Our current scripts won't
654include anything beyond the first line. The script has no way of knowing when
655the release note actually stops.
656```
657
658``` {.bad}
659Relnote: This is an INVALID multi-line release note. "Quotes" need to be
660 escaped in order for them to be parsed properly.
661```
662
663### Common build errors
664
665#### Diagnosing build failures
666
667If you've encountered a build failure and you're not sure what is triggering it,
668then please run
669`./development/diagnose-build-failure/diagnose-build-failure.sh`.
670
671This script can categorize your build failure into one of the following
672categories:
673
674* The Gradle Daemon is saving state in memory and triggering a failure
675* Your source files have been changed and/or incompatible git commits have
676 been checked out
677* Some file in the out/ dir is triggering an error
678 * If this happens, diagnose-build-failure.sh should also identify which
679 file(s) specifically
680* The build is nondeterministic and/or affected by timestamps
681* The build via gradlew actually passes and this build failure is specific to
682 Android Studio
683
684Some more-specific build failures are listed below in this page.
685
686#### Out-of-date platform prebuilts
687
688Like a normal Android library developed in Android Studio, libraries within
689`androidx` are built against prebuilts of the platform SDK. These are checked in
690to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
691
692If you are developing against pre-release platform APIs in the internal
693`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
694the latest API changes.
695
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000696#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000697
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800698If Gradle cannot resolve a dependency listed in your `build.gradle`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000699
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800700* You will probably want to import the missing artifact via
701 [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md)
702
703 * We store artifacts in the prebuilts repositories under
704 `prebuilts/androidx` to facilitate reproducible builds even if remote
705 artifacts are changed.
706
707* You may need to [establish trust for](#dependency-verification) the new
708 artifact
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000709
AndroidX Core Teambae52562022-07-06 13:41:40 -0700710##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000711
712Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700713[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
714Update this file to include a constant for the version of the library that you
715want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000716`build.gradle` dependencies.
717
AndroidX Core Teambae52562022-07-06 13:41:40 -0700718**After** you update the `libs.versions.toml` file with new dependencies, you
719can download them by running:
720
721```shell
722cd frameworks/support &&\
723development/importMaven/importMaven.sh import-toml
724```
725
726This command will resolve everything declared in the `libs.versions.toml` file
727and download missing artifacts into `prebuilts/androidx/external` or
728`prebuilts/androidx/internal`.
729
730Make sure to upload these changes before or concurrently (ex. in the same Gerrit
731topic) with the dependent library code.
732
733##### Downloading a dependency without changing `libs.versions.toml`
734
735You can also download a dependency without changing `libs.versions.toml` file by
736directly invoking:
737
738```shell
739cd frameworks/support &&\
740./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
741```
742
743##### Missing konan dependencies
744
745Kotlin Multiplatform projects need prebuilts to compile native code, which are
746located under `prebuilts/androidx/konan`. **After** you update the kotlin
747version of AndroidX, you should also download necessary prebuilts via:
748
749```shell
750cd frameworks/support &&\
751development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
752```
753
754Please remember to commit changes in the `prebuilts/androidx/konan` repository.
755
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000756#### Dependency verification
757
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800758If you import a new dependency that is either unsigned or is signed with a new,
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000759unrecognized key, then you will need to add new dependency verification metadata
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800760to indicate to Gradle that this new dependency is trusted. See the instructions
761[here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000762
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000763#### Updating an existing dependency
764
765If an older version of a dependency prebuilt was already checked in, please
766manually remove it within the same CL that adds the new prebuilt. You will also
767need to update `Dependencies.kt` to reflect the version change.
768
769#### My gradle build fails with "Cannot invoke method getURLs() on null object"
770
771You're using Java 9's javac, possibly because you ran envsetup.sh from the
772platform build or specified Java 9 as the global default Java compiler. For the
773former, you can simply open a new shell and avoid running envsetup.sh. For the
774latter, we recommend you set Java 8 as the default compiler using sudo
775update-java-alternatives; however, if you must use Java 9 as the default then
776you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
777
778#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
779
780You probably need to update the prebuilt SDK used by the gradle build. If you
781are referencing new framework APIs, you will need to wait for the framework
782changes to land in an SDK build (or build it yourself) and then land in both
783prebuilts/fullsdk and prebuilts/sdk. See
Ian Baker186108e2023-11-20 06:54:36 -0800784[Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk)
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500785for more information.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000786
787#### How do I handle refactoring a framework API referenced from a library?
788
789Because AndroidX must compile against both the current framework and the latest
790SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
AndroidX Core Team5ad2f7f2023-01-20 12:26:18 -0500791will need to refactor in stages:
792
7931. Remove references to the target APIs from AndroidX
7942. Perform the refactoring in the framework
7953. Update the framework prebuilt SDK to incorporate changes in (2)
7964. Add references to the refactored APIs in AndroidX
7975. Update AndroidX prebuilts to incorporate changes in (4)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000798
799## Testing {#testing}
800
801AndroidX libraries are expected to include unit or integration test coverage for
802100% of their public API surface. Additionally, all CLs must include a `Test:`
803stanza indicating which tests were used to verify correctness. Any CLs
804implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000805the issue being fixed.
806
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700807### Running tests {#run-tests}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000808
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700809Generally, tests in the AndroidX repository should be run through the Android
810Studio UI. You can also run tests from the command line or via remote devices on
811FTL, see
Ian Baker186108e2023-11-20 06:54:36 -0800812[Running unit and integration tests](/docs/testing.md#running)
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700813for details.
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000814
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700815#### Single test class or method
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000816
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008171. Open the desired test file in Android Studio
8182. Right-click on a test class or `@Test` method name and select `Run <name>`
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000819
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700820#### Full test package
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000821
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008221. In the `Project` side panel, open the desired module
8232. Find the package directory with the tests
8243. Right-click on the directory and select `Run <package>`
825
826### Running sample apps {#run-samples}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000827
828The AndroidX repository has a set of Android applications that exercise AndroidX
829code. These applications can be useful when you want to debug a real running
830application, or reproduce a problem interactively, before writing test code.
831
832These applications are named either `<libraryname>-integration-tests-testapp`,
833or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
834can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000835
Ian Baker186108e2023-11-20 06:54:36 -0800836See the [Testing](/docs/testing.md) page for more resources on
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500837writing, running, and monitoring tests.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000838
839### AVD Manager
840
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000841The Android Studio instance started by `./studiow` uses a custom SDK directory,
842which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700843Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000844unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000845
846You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700847artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000848directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000849
850```shell
851# Using the default MacOS Android SDK directory...
852ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
853 ../../prebuilts/fullsdk-darwin/system-images
854```
855
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000856## Library snapshots {#snapshots}
857
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000858### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000859
860Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000861snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000862
863```groovy {highlight=context:[buildId]}
864allprojects {
865 repositories {
866 google()
867 jcenter()
868 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
869 }
870}
871```
872
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000873You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
874for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000875
876```groovy {highlight=context:SNAPSHOT}
877dependencies {
878 implementation "androidx.core:core:1.2.0-SNAPSHOT"
879}
880```
881
882### Where to find snapshots
883
884If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
885can find them on either our public-facing build server:
886
887`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
888
889or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
890
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700891`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
892build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000893
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700894`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000895
896### Obtaining a build ID
897
898To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000899[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000900on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
901androidx.dev site.
902
903Note that if you are using androidx.dev, you may substitute `latest` for a build
904ID to use the last known good build.
905
906To manually find the last known good `build-id`, you have several options.
907
908#### Snapshots on androidx.dev
909
910[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
911usable builds.
912
913#### Programmatically via `jq`
914
915Install `jq`:
916
917```shell
918sudo apt-get install jq
919```
920
921```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000922ID=`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 Team2e416b22020-12-03 22:58:07 +0000923 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
924```
925
926#### Android build server
927
928Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000929[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000930on ci.android.com.
931
932For `androidx-snapshot` target, wait for the green "last known good build"
933button to load and then click it to follow it to the build artifact URL.
934
935### Using in a Gradle build
936
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500937To make these artifacts visible to Gradle, you need to add it as a repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000938
939```groovy
940allprojects {
941 repositories {
942 google()
943 maven {
944 // For all Jetpack libraries (including Compose)
945 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
946 }
947 }
948}
949```
950
951Note that the above requires you to know the `build-id` of the snapshots you
952want.
953
954#### Specifying dependencies
955
956All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
957to use a snapshot artifact, the version in your `build.gradle` will need to be
958updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
959
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500960For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000961following to your `build.gradle`:
962
963```
964dependencies {
965 ...
966 implementation("androidx.core:core:1.2.0-SNAPSHOT")
967 ...
968}
969```
970
971## FAQ {#faq}
972
973### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
974
975If you're working on a new feature or bug fix in AndroidX, you may want to test
976your changes against another project to verify that the change makes sense in a
977real-world context or that a bug's specific repro case has been fixed.
978
979If you need to be absolutely sure that your test will exactly emulate the
980developer's experience, you can repeatedly build the AndroidX archive and
981rebuild your application. In this case, you will need to create a local build of
982AndroidX's local Maven repository artifact and install it in your Android SDK
983path.
984
985First, use the `createArchive` Gradle task to generate the local Maven
986repository artifact:
987
988```shell
AndroidX Core Teamcb7de292024-08-07 14:25:42 -0700989# Creates <path-to-checkout>/out/repository/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000990./gradlew createArchive
991```
992
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700993Using your alternate (non-AndroidX) version of Android Studio open the project's
994`settings.gradle.kts` and add the following within
995`dependencyResolutionManagement` to make your project look for binaries in the
996newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000997
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700998```kotlin
999dependencyResolutionManagement {
1000 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001001 repositories {
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001002 google()
1003 mavenCentral()
1004 // Add this
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001005 maven {
AndroidX Core Teamcb7de292024-08-07 14:25:42 -07001006 setUrl("<path-to-sdk>/out/repository/")
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001007 }
1008 }
1009}
1010```
1011
1012NOTE Gradle resolves dependencies in the order that the repositories are defined
1013(if 2 repositories can resolve the same dependency, the first listed will do so
1014and the second will not). Therefore, if the library you are testing has the same
1015group, artifact, and version as one already published, you will want to list
1016your custom maven repo first.
1017
1018Finally, in the dependencies section of your standalone project's `build.gradle`
1019file, add or update the `implementation` entries to reflect the AndroidX modules
1020that you would like to test. Example:
1021
1022```
1023dependencies {
1024 ...
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001025 implementation "androidx.appcompat:appcompat:1.0.0-alpha02"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001026}
1027```
1028
1029If you are testing your changes in the Android Platform code, you can replace
1030the module you are testing
1031`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1032module. We recommend only replacing the module you are modifying instead of the
1033full m2repository to avoid version issues of other modules. You can either take
1034the unzipped directory from
1035`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
AndroidX Core Teamcb7de292024-08-07 14:25:42 -07001036`<path-to-checkout>/out/repository/` after building `androidx`. Here is an
1037example of replacing the RecyclerView module:
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001038
1039```shell
1040$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1041rm -rf $TARGET;
1042cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1043```
1044
1045Make sure the library versions are the same before and after replacement. Then
1046you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001047
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001048### How do I add content to a library's Overview reference doc page?
1049
1050Put content in a markdown file that ends with `-documentation.md` in the
1051directory that corresponds to the Overview page that you'd like to document.
1052
1053For example, the `androidx.compose.runtime`
1054[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1055includes content from
1056[compose-runtime-documentation.md](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/compose-runtime-documentation.md).
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001057
1058### How do I enable MultiDex for my library?
1059
AndroidX Core Team5c7f3df2024-06-24 12:06:54 -07001060It is enabled automatically as androidx minSdkVersion is API >=21.