blob: 82a298371ab4d29d3343fcb889dfa29d0c1e4ff3 [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
103Like ChromeOS, Chromium, and the Android build system, we develop in the open as
104much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000105[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000106branch of the Android Open Source Project.
107
AndroidX Core Team95040f72024-10-10 14:31:18 -0700108As of 2024/10/10, you will need about XXX GB for a clean checkout or YYY GB for
109a fully-built checkout.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000110
111### Synchronize the branch {#source-checkout}
112
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000113Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000114
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500115#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000116
117All development should occur in this branch unless otherwise specified by the
118AndroidX Core team.
119
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000120The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000121
122```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000123mkdir androidx-main && cd androidx-main
alanv7ae48942022-09-27 13:53:32 -0700124repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000125 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team95040f72024-10-10 14:31:18 -0700126repo sync -c -j32
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000127```
128
129NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
130you may need to install Python3 and boot strap the SSL certificates in the
131included version of pip. You can execute `Install Certificates.command` under
132`/Applications/Python 3.6/` to do so.
133
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400134NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
135failed with exit status -6` with cause `md_enable: algorithm 10 not available`
136you may need to install a build of `gpg` that supports SHA512, such as the
137latest version available from [Homebrew](https://brew.sh/) using `brew install
138gpg`.
139
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000140### Increase Git rename limit {#source-config}
141
142To ensure `git` can detect diffs and renames across significant changes (namely,
143the `androidx.*` package rename), we recommend that you set the following `git
144config` properties:
145
146```shell
147git config --global merge.renameLimit 999999
148git config --global diff.renameLimit 999999
149```
150
alanv207674d2022-06-14 11:20:52 -0700151### Set up Git file exclusions {#source-exclude}
152
153Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
154avoid accidentally checking in local metadata files:
155
156```shell
157echo .DS_Store>>~/.gitignore
158git config --global core.excludesFile '~/.gitignore'
159```
160
161### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400162
163The
164[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
165contains a history of the matching exact commits of each git repository over
166time, and it can be
167[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
168
alanve9101e42022-01-28 12:05:11 -0800169### Troubleshooting
170
171> NOTE: If the repo manifest changes -- for example when we update the version
172> of `platform-tools` by pointing it to a different git project -- you may see
173> the following error during`repo sync`:
174>
175> ```shell
176> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
177> ...
178> error: Unable to fully sync the tree.
179> error: Downloading network changes failed.
180> ```
181>
182> This indicates that Studio or some other process has made changes in the git
183> project that has been replaced or removed. You can force `repo sync` to
184> discard these changes and check out the correct git project by adding the
185> `--force-sync` argument:
186>
187> ```shell
188> repo sync -j32 --force-sync
189> ```
190
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000191## Explore source code from a browser {#code-search}
192
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000193`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000194[code search](https://cs.android.com/androidx/platform/frameworks/support) that
195allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000196URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000197
AndroidX Core Team110f54d2022-10-24 08:35:31 -0700198### Custom search engine for `androidx-main` {#custom-search-engine}
199
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000200We recommend setting up a custom search engine in Chrome as a faster (and
201publicly-accessible) alternative to `cs/`.
202
AndroidX Core Team2e416b22020-12-03 22:58:07 +00002031. Open `chrome://settings/searchEngines`
2041. Click the `Add` button
2051. Enter a name for your search engine, ex. "AndroidX Code Search"
2061. Enter a keyword, ex. "csa"
2071. Enter the following URL:
208 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
2091. Click the `Add` button
210
211Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
212query to search for, e.g. `AppCompatButton file:appcompat`, and press the
213`Enter` key to get to the search result page.
214
215## Develop in Android Studio {#studio}
216
217Library development uses a curated version of Android Studio to ensure
218compatibility between various components of the development workflow.
219
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000220From the `frameworks/support` directory, you can use `./studiow m` (short for
221`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400222correct version of Studio to work on the `main` set of androidx projects
223(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000224[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
225also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400226projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000227
228Next, open the `framework/support` project root from your checkout. If Studio
229asks you which SDK you would like to use, select `Use project SDK`. Importing
230projects may take a while, but once that finishes you can use Studio as you
231normally would for application or library development -- right-click on a test
232or sample to run or debug it, search through classes, and so on.
233
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000234> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
235> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
236> opening `File > Project Structure > Platform Settings > SDKs` and manually
237> setting the Android SDK home path to
238> `<project-root>/prebuilts/fullsdk-<platform>`.
239
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500240### Troubleshooting {#studio-troubleshooting}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000241
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500242* If you've updated to macOS Ventura and receive a "xcrun: error: invalid
243 active developer path" message when running Studio, reinstall Xcode using
244 `xcode-select --install`. If that does not work, you will need to download
245 Xcode.
246* If you get a “Unregistered VCS root detected” message, click “Add root” to
247 enable the Git/VCS integration for Android Studio.
248* If you see any errors (red underlines), click Gradle's elephant button in
249 the toolbar (or `File > Sync Project with Gradle Files`) and they should
250 resolve once the build completes.
251* If you run `./studiow` with a new project set but you're still seeing the
252 old project set in `Project`, use `File > Sync Project with Gradle Files` to
253 force a re-sync.
254* If Android Studio's UI looks scaled up, ex. twice the size it should be, you
255 may need to add the following line to your `studio64.vmoptions` file using
256 `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false`
257* If you don't see a specific Gradle task listed in Studio's Gradle pane,
258 check the following:
259 * Studio might be running a different project subset than the one
260 intended. For example, `./studiow main` only loads the `main` set of
261 androidx projects; run `./studiow compose` to load the tasks specific to
262 Compose.
263 * Gradle tasks aren't being loaded. Under Studio's settings =>
264 Experimental, make sure that "Do not build Gradle task list during
265 Gradle sync" is unchecked. Note that unchecking this can reduce Studio's
266 performance.
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700267
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000268If in the future you encounter unexpected errors in Studio and you want to check
269for the possibility it is due to some incorrect settings or other generated
270files, you can run `./studiow --clean main <project subset>` or `./studiow
271--reinstall <project subset>` to clean generated files or reinstall Studio.
272
alanv07cfb5e2022-10-12 11:14:08 -0700273### Enabling Compose `@Preview` annotation previews
AndroidX Core Team6173c652022-05-19 20:43:28 +0000274
alanv07cfb5e2022-10-12 11:14:08 -0700275Add the following dependencies to your project's `build.gradle`:
AndroidX Core Team6173c652022-05-19 20:43:28 +0000276
277```groovy
278dependencies {
279 implementation(project(":compose:ui:ui-tooling-preview"))
280 debugImplementation(project(":compose:ui:ui-tooling"))
281}
282```
283
alanv07cfb5e2022-10-12 11:14:08 -0700284Then,
AndroidX Core Team6173c652022-05-19 20:43:28 +0000285[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
286
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000287## Making changes {#changes}
288
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000289Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000290CL-specific working branches. Use `repo` to create, upload, and abandon local
291branches. Use `git` to manage changes within a local branch.
292
293```shell
294cd path/to/checkout/frameworks/support/
295repo start my_branch_name .
296# make necessary code changes
297# use git to commit changes
298repo upload --cbr -t .
299```
300
301The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000302`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
303can refer to the
304[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
305for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000306
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000307If you see the following prompt, choose `always`:
308
309```
310Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
311```
312
313If the upload succeeds, you'll see an output like:
314
315```
316remote:
317remote: New Changes:
318remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
319remote:
320```
321
322To edit your change, use `git commit --amend`, and re-upload.
323
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000324NOTE If you encounter issues with `repo upload`, consider running upload with
325trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
326logs can be helpful for reporting issues to the team that manages our git
327servers.
328
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000329NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
330skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
331hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
332to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
333
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700334### Fixing Kotlin code style errors
335
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700336`repo upload` automatically runs `ktfmt`, which will cause the upload to fail if
337your code has style errors, which it reports on the command line like so:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700338
339```
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700340[FAILED] ktfmt_hook
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700341 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
342```
343
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700344To find and fix these errors, you can run ktfmt locally, either in a console
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700345window or in the Terminal tool in Android Studio. Running in the Terminal tool
346is preferable because it will surface links to your source files/lines so you
347can easily navigate to the code to fix any problems.
348
349First, to run the tool and see all of the errors, run:
350
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700351`./gradlew module:submodule:ktCheck`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700352
353where module/submodule are the names used to refer to the module you want to
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700354check, such as `navigation:navigation-common`. You can also run ktfmt on the
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700355entire project, but that takes longer as it is checking all active modules in
356your project.
357
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700358Many of the errors that ktfmt finds can be automatically fixed by running
359ktFormat:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700360
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700361`./gradlew module:submodule:ktFormat`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700362
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700363ktFormat will report any remaining errors, but you can also run `ktCheck` again
364at any time to see an updated list of the remaining errors.
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700365
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000366## Building {#building}
367
368### Modules and Maven artifacts {#modules-and-maven-artifacts}
369
370To build a specific module, use the module's `assemble` Gradle task. For
371example, if you are working on `core` module use:
372
373```shell
374./gradlew core:core:assemble
375```
376
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000377To make warnings fail your build (same as presubmit), use the `--strict` flag,
378which our gradlew expands into a few correctness-related flags including
AndroidX Core Team9d812cd2022-09-01 15:42:06 -0700379`-Pandroidx.validateNoUnrecognizedMessages`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000380
381```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000382./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000383```
384
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500385To build every module and generate the local Maven repository artifact, use the
386`createArchive` Gradle task:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000387
388```shell
389./gradlew createArchive
390```
391
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000392To run the complete build task that our build servers use, use the corresponding
393shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000394
395```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000396./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000397```
398
399### Attaching a debugger to the build
400
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700401Gradle tasks, including building a module, may be run or debugged from within
402Android Studio. To start, you need to add the task as a run configuration: you
403can do this manually by adding the corresponding task by clicking on the run
404configuration dropdown, pressing
405[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
406and adding the corresponding task.
407
408You can also run the task through the IDE from the terminal, by using the
409[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
410feature - type in the task you want to run in the in-IDE terminal, and
411`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
412automatically add the configuration to the run configuration menu - you can then
413cancel the task.
414
415Once the task has been added to the run configuration menu, you can start
416debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000417
418Note that debugging will not be available until Gradle sync has completed.
419
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000420#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000421
422Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000423`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000424
AndroidX Core Team6173c652022-05-19 20:43:28 +00004251. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004261. Click the plus in the top left to create a new "Remote" configuration. Give
427 it a name and hit "Ok".
4281. Set breakpoints.
4291. Run your task with added flags: `./gradlew <your_task_here>
430 -Dorg.gradle.debug=true --no-daemon`
4311. Hit the "Debug" button to the right of the configuration dropdown to attach
432 to the process.
433
434#### Troubleshooting the debugger
435
436If you get a "Connection refused" error, it's likely because a gradle daemon is
437still running on the port specified in the config, and you can fix this by
438killing the running gradle daemons:
439
440```shell
441./gradlew --stop
442```
443
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000444NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000445[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
446
447#### Attaching to an annotation processor
448
449Annotation processors run as part of the build, to debug them is similar to
450debugging the build.
451
452For a Java project:
453
454```shell
455./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
456```
457
458For a Kotlin project:
459
460```shell
461./gradlew <your_project>:compileDebugKotlin --no-daemon --rerun-tasks -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket\,address=5005\,server=y\,suspend=n"
462```
463
464### Optional: Enabling internal menu in IntelliJ/Studio
465
466To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
467Android Lint checks and Metalava, you can enable the
468[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
469which is typically used for plugin and IDE development.
470
471### Reference documentation {#docs}
472
473Our reference docs (Javadocs and KotlinDocs) are published to
474https://developer.android.com/reference/androidx/packages and may be built
475locally.
476
477NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
478run `./gradlew tasks`
479
AndroidX Core Team76f65452024-01-02 11:39:57 -0800480#### Generate docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700481
482To build API reference docs for both Java and Kotlin source code using Dackka,
483run the Gradle task:
484
485```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500486./gradlew docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700487```
488
489Location of generated refdocs:
490
491* docs-public (what is published to DAC):
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500492 `{androidx-main}/out/androidx/docs-public/build/docs`
493* docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700494
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700495The generated docs are plain HTML pages with links that do not work locally.
496These issues are fixed when the docs are published to DAC, but to preview a
497local version of the docs with functioning links and CSS, run:
498
499```
500python3 development/offlinifyDocs/offlinify_dackka_docs.py
501```
502
503You will need to have the `bs4` Python package installed. The CSS used is not
504the same as what will be used when the docs are published.
505
506By default, this command converts the tip-of-tree docs for all libraries. To see
507more options, run:
508
509```
510python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
511```
512
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000513#### Release docs
514
515To build API reference docs for published artifacts formatted for use on
516[d.android.com](http://d.android.com), run the Gradle command:
517
518```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500519./gradlew zipDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000520```
521
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500522This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This
523command builds docs based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000524`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
525the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000526`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000527colloquially refer to this two step process of (1) updating `docs-public` and
528(2) checking in a prebuilt artifact into the prebuilts directory as
Ian Baker186108e2023-11-20 06:54:36 -0800529[The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™).
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500530So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000531https://developer.android.com/reference/androidx/packages, both of these steps
532need to be completed.
533
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000534### Updating public APIs {#updating-public-apis}
535
536Public API tasks -- including tracking, linting, and verifying compatibility --
537are run under the following conditions based on the `androidx` configuration
538block, evaluated in order:
539
540* `runApiTasks=Yes` => yes
541* `runApiTasks=No` => no
542* `toolingProject=true` => no
543* `mavenVersion` or group version not set => no
544* Has an existing `api/` directory => yes
545* `publish=SNAPSHOT_AND_RELEASE` => yes
546* Otherwise, no
547
548If you make changes to tracked public APIs, you will need to acknowledge the
549changes by updating the `<component>/api/current.txt` and associated API files.
550This is handled automatically by the `updateApi` Gradle task:
551
552```shell
553# Run updateApi for all modules.
554./gradlew updateApi
555
556# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
557./gradlew :appcompat:appcompat-resources:updateApi
558```
559
560If you change the public APIs without updating the API file, your module will
561still build **but** your CL will fail Treehugger presubmit checks.
562
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500563NOTE The `updateApi` task does not generate versioned API files (e.g.
564`1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task
565will always generate `current.txt` API files.
566
alanva5fd21b2021-08-20 10:26:46 -0700567#### What are all these files in `api/`? {#updating-public-apis-glossary}
568
569Historical API surfaces are tracked for compatibility and docs generation
570purposes. For each version -- including `current` to represent the tip-of-tree
571version -- we record three different types of API surfaces.
572
573* `<version>.txt`: Public API surface, tracked for compatibility
574* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
575 compatibility where necessary (see
Ian Baker186108e2023-11-20 06:54:36 -0800576 [Restricted APIs](/docs/api_guidelines/index.md#restricted-api))
alanva5fd21b2021-08-20 10:26:46 -0700577* `public_plus_experimental_<version>.txt`: Public API surface plus
578 `@RequiresOptIn` experimental API surfaces used for documentation (see
Ian Baker186108e2023-11-20 06:54:36 -0800579 [Experimental APIs](/docs/api_guidelines/index.md#experimental-api))
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500580 and API review
alanva5fd21b2021-08-20 10:26:46 -0700581
AndroidX Core Teamf2f418d2024-07-24 11:02:09 -0700582NOTE: Experimental API tracking for KLib is enabled by default for KMP projects
583via parallel `updateAbi` and `checkAbi` tasks. If you have a problem with these
584tools,
585[please file an issue](https://issuetracker.google.com/issues/new?component=1102332&template=1780493).
586As a workaround, you may opt-out by setting
587`enableBinaryCompatibilityValidator = false` under
588`AndroidxMultiplatformExtension` in your library's `build.gradle` file.
589
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000590### Release notes & the `Relnote:` tag {#relnote}
591
592Prior to releasing, release notes are pre-populated using a script and placed
593into a Google Doc. The Google Doc is manually double checked by library owners
594before the release goes live. To auto-populate your release notes, you can use
595the semi-optional commit tag `Relnote:` in your commit, which will automatically
596include that message the commit in the pre-populated release notes.
597
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000598The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000599
600#### How to use it?
601
602One-line release note:
603
604``` {.good}
605Relnote: Fixed a critical bug
606```
607
608``` {.good}
609Relnote: "Fixed a critical bug"
610```
611
612``` {.good}
613Relnote: Added the following string function: `myFoo(\"bar\")`
614```
615
616Multi-line release note:
617
618Note: If the following lines do not contain an indent, you may hit b/165570183.
619
620``` {.good}
621Relnote: "We're launching this awesome new feature! It solves a whole list of
622 problems that require a lot of explaining! "
623```
624
625``` {.good}
626Relnote: """Added the following string function: `myFoo("bar")`
627 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
628 """
629```
630
631Opt out of the Relnote tag:
632
633``` {.good}
634Relnote: N/A
635```
636
637``` {.good}
638Relnote: NA
639```
640
641NOT VALID:
642
643``` {.bad}
644Relnote: This is an INVALID multi-line release note. Our current scripts won't
645include anything beyond the first line. The script has no way of knowing when
646the release note actually stops.
647```
648
649``` {.bad}
650Relnote: This is an INVALID multi-line release note. "Quotes" need to be
651 escaped in order for them to be parsed properly.
652```
653
654### Common build errors
655
656#### Diagnosing build failures
657
658If you've encountered a build failure and you're not sure what is triggering it,
659then please run
660`./development/diagnose-build-failure/diagnose-build-failure.sh`.
661
662This script can categorize your build failure into one of the following
663categories:
664
665* The Gradle Daemon is saving state in memory and triggering a failure
666* Your source files have been changed and/or incompatible git commits have
667 been checked out
668* Some file in the out/ dir is triggering an error
669 * If this happens, diagnose-build-failure.sh should also identify which
670 file(s) specifically
671* The build is nondeterministic and/or affected by timestamps
672* The build via gradlew actually passes and this build failure is specific to
673 Android Studio
674
675Some more-specific build failures are listed below in this page.
676
677#### Out-of-date platform prebuilts
678
679Like a normal Android library developed in Android Studio, libraries within
680`androidx` are built against prebuilts of the platform SDK. These are checked in
681to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
682
683If you are developing against pre-release platform APIs in the internal
684`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
685the latest API changes.
686
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000687#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000688
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800689If Gradle cannot resolve a dependency listed in your `build.gradle`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000690
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800691* You will probably want to import the missing artifact via
692 [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md)
693
694 * We store artifacts in the prebuilts repositories under
695 `prebuilts/androidx` to facilitate reproducible builds even if remote
696 artifacts are changed.
697
698* You may need to [establish trust for](#dependency-verification) the new
699 artifact
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000700
AndroidX Core Teambae52562022-07-06 13:41:40 -0700701##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000702
703Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700704[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
705Update this file to include a constant for the version of the library that you
706want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000707`build.gradle` dependencies.
708
AndroidX Core Teambae52562022-07-06 13:41:40 -0700709**After** you update the `libs.versions.toml` file with new dependencies, you
710can download them by running:
711
712```shell
713cd frameworks/support &&\
714development/importMaven/importMaven.sh import-toml
715```
716
717This command will resolve everything declared in the `libs.versions.toml` file
718and download missing artifacts into `prebuilts/androidx/external` or
719`prebuilts/androidx/internal`.
720
721Make sure to upload these changes before or concurrently (ex. in the same Gerrit
722topic) with the dependent library code.
723
724##### Downloading a dependency without changing `libs.versions.toml`
725
726You can also download a dependency without changing `libs.versions.toml` file by
727directly invoking:
728
729```shell
730cd frameworks/support &&\
731./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
732```
733
734##### Missing konan dependencies
735
736Kotlin Multiplatform projects need prebuilts to compile native code, which are
737located under `prebuilts/androidx/konan`. **After** you update the kotlin
738version of AndroidX, you should also download necessary prebuilts via:
739
740```shell
741cd frameworks/support &&\
742development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
743```
744
745Please remember to commit changes in the `prebuilts/androidx/konan` repository.
746
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000747#### Dependency verification
748
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800749If you import a new dependency that is either unsigned or is signed with a new,
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000750unrecognized key, then you will need to add new dependency verification metadata
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800751to indicate to Gradle that this new dependency is trusted. See the instructions
752[here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000753
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000754#### Updating an existing dependency
755
756If an older version of a dependency prebuilt was already checked in, please
757manually remove it within the same CL that adds the new prebuilt. You will also
758need to update `Dependencies.kt` to reflect the version change.
759
760#### My gradle build fails with "Cannot invoke method getURLs() on null object"
761
762You're using Java 9's javac, possibly because you ran envsetup.sh from the
763platform build or specified Java 9 as the global default Java compiler. For the
764former, you can simply open a new shell and avoid running envsetup.sh. For the
765latter, we recommend you set Java 8 as the default compiler using sudo
766update-java-alternatives; however, if you must use Java 9 as the default then
767you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
768
769#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
770
771You probably need to update the prebuilt SDK used by the gradle build. If you
772are referencing new framework APIs, you will need to wait for the framework
773changes to land in an SDK build (or build it yourself) and then land in both
774prebuilts/fullsdk and prebuilts/sdk. See
Ian Baker186108e2023-11-20 06:54:36 -0800775[Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk)
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500776for more information.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000777
778#### How do I handle refactoring a framework API referenced from a library?
779
780Because AndroidX must compile against both the current framework and the latest
781SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
AndroidX Core Team5ad2f7f2023-01-20 12:26:18 -0500782will need to refactor in stages:
783
7841. Remove references to the target APIs from AndroidX
7852. Perform the refactoring in the framework
7863. Update the framework prebuilt SDK to incorporate changes in (2)
7874. Add references to the refactored APIs in AndroidX
7885. Update AndroidX prebuilts to incorporate changes in (4)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000789
790## Testing {#testing}
791
792AndroidX libraries are expected to include unit or integration test coverage for
793100% of their public API surface. Additionally, all CLs must include a `Test:`
794stanza indicating which tests were used to verify correctness. Any CLs
795implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000796the issue being fixed.
797
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700798### Running tests {#run-tests}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000799
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700800Generally, tests in the AndroidX repository should be run through the Android
801Studio UI. You can also run tests from the command line or via remote devices on
802FTL, see
Ian Baker186108e2023-11-20 06:54:36 -0800803[Running unit and integration tests](/docs/testing.md#running)
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700804for details.
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000805
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700806#### Single test class or method
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000807
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008081. Open the desired test file in Android Studio
8092. Right-click on a test class or `@Test` method name and select `Run <name>`
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000810
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700811#### Full test package
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000812
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008131. In the `Project` side panel, open the desired module
8142. Find the package directory with the tests
8153. Right-click on the directory and select `Run <package>`
816
817### Running sample apps {#run-samples}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000818
819The AndroidX repository has a set of Android applications that exercise AndroidX
820code. These applications can be useful when you want to debug a real running
821application, or reproduce a problem interactively, before writing test code.
822
823These applications are named either `<libraryname>-integration-tests-testapp`,
824or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
825can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000826
Ian Baker186108e2023-11-20 06:54:36 -0800827See the [Testing](/docs/testing.md) page for more resources on
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500828writing, running, and monitoring tests.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000829
830### AVD Manager
831
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000832The Android Studio instance started by `./studiow` uses a custom SDK directory,
833which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700834Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000835unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000836
837You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700838artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000839directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000840
841```shell
842# Using the default MacOS Android SDK directory...
843ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
844 ../../prebuilts/fullsdk-darwin/system-images
845```
846
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000847## Library snapshots {#snapshots}
848
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000849### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000850
851Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000852snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000853
854```groovy {highlight=context:[buildId]}
855allprojects {
856 repositories {
857 google()
858 jcenter()
859 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
860 }
861}
862```
863
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000864You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
865for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000866
867```groovy {highlight=context:SNAPSHOT}
868dependencies {
869 implementation "androidx.core:core:1.2.0-SNAPSHOT"
870}
871```
872
873### Where to find snapshots
874
875If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
876can find them on either our public-facing build server:
877
878`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
879
880or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
881
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700882`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
883build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000884
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700885`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000886
887### Obtaining a build ID
888
889To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000890[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000891on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
892androidx.dev site.
893
894Note that if you are using androidx.dev, you may substitute `latest` for a build
895ID to use the last known good build.
896
897To manually find the last known good `build-id`, you have several options.
898
899#### Snapshots on androidx.dev
900
901[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
902usable builds.
903
904#### Programmatically via `jq`
905
906Install `jq`:
907
908```shell
909sudo apt-get install jq
910```
911
912```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000913ID=`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 +0000914 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
915```
916
917#### Android build server
918
919Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000920[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000921on ci.android.com.
922
923For `androidx-snapshot` target, wait for the green "last known good build"
924button to load and then click it to follow it to the build artifact URL.
925
926### Using in a Gradle build
927
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500928To make these artifacts visible to Gradle, you need to add it as a repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000929
930```groovy
931allprojects {
932 repositories {
933 google()
934 maven {
935 // For all Jetpack libraries (including Compose)
936 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
937 }
938 }
939}
940```
941
942Note that the above requires you to know the `build-id` of the snapshots you
943want.
944
945#### Specifying dependencies
946
947All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
948to use a snapshot artifact, the version in your `build.gradle` will need to be
949updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
950
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500951For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000952following to your `build.gradle`:
953
954```
955dependencies {
956 ...
957 implementation("androidx.core:core:1.2.0-SNAPSHOT")
958 ...
959}
960```
961
962## FAQ {#faq}
963
964### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
965
966If you're working on a new feature or bug fix in AndroidX, you may want to test
967your changes against another project to verify that the change makes sense in a
968real-world context or that a bug's specific repro case has been fixed.
969
970If you need to be absolutely sure that your test will exactly emulate the
971developer's experience, you can repeatedly build the AndroidX archive and
972rebuild your application. In this case, you will need to create a local build of
973AndroidX's local Maven repository artifact and install it in your Android SDK
974path.
975
976First, use the `createArchive` Gradle task to generate the local Maven
977repository artifact:
978
979```shell
AndroidX Core Teamcb7de292024-08-07 14:25:42 -0700980# Creates <path-to-checkout>/out/repository/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000981./gradlew createArchive
982```
983
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700984Using your alternate (non-AndroidX) version of Android Studio open the project's
985`settings.gradle.kts` and add the following within
986`dependencyResolutionManagement` to make your project look for binaries in the
987newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000988
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700989```kotlin
990dependencyResolutionManagement {
991 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000992 repositories {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700993 google()
994 mavenCentral()
995 // Add this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000996 maven {
AndroidX Core Teamcb7de292024-08-07 14:25:42 -0700997 setUrl("<path-to-sdk>/out/repository/")
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000998 }
999 }
1000}
1001```
1002
1003NOTE Gradle resolves dependencies in the order that the repositories are defined
1004(if 2 repositories can resolve the same dependency, the first listed will do so
1005and the second will not). Therefore, if the library you are testing has the same
1006group, artifact, and version as one already published, you will want to list
1007your custom maven repo first.
1008
1009Finally, in the dependencies section of your standalone project's `build.gradle`
1010file, add or update the `implementation` entries to reflect the AndroidX modules
1011that you would like to test. Example:
1012
1013```
1014dependencies {
1015 ...
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001016 implementation "androidx.appcompat:appcompat:1.0.0-alpha02"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001017}
1018```
1019
1020If you are testing your changes in the Android Platform code, you can replace
1021the module you are testing
1022`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1023module. We recommend only replacing the module you are modifying instead of the
1024full m2repository to avoid version issues of other modules. You can either take
1025the unzipped directory from
1026`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
AndroidX Core Teamcb7de292024-08-07 14:25:42 -07001027`<path-to-checkout>/out/repository/` after building `androidx`. Here is an
1028example of replacing the RecyclerView module:
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001029
1030```shell
1031$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1032rm -rf $TARGET;
1033cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1034```
1035
1036Make sure the library versions are the same before and after replacement. Then
1037you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001038
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001039### How do I add content to a library's Overview reference doc page?
1040
1041Put content in a markdown file that ends with `-documentation.md` in the
1042directory that corresponds to the Overview page that you'd like to document.
1043
1044For example, the `androidx.compose.runtime`
1045[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1046includes content from
1047[compose-runtime-documentation.md](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/compose-runtime-documentation.md).
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001048
1049### How do I enable MultiDex for my library?
1050
AndroidX Core Team5c7f3df2024-06-24 12:06:54 -07001051It is enabled automatically as androidx minSdkVersion is API >=21.