blob: 907eb6c7d9baa9f5f5bfc527fd2d12f0012db00f [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
20### Linux and MacOS {#setup-linux-mac}
21
22First, download `repo` using `curl`.
23
24```shell
25test -d ~/bin || mkdir ~/bin
26curl https://storage.googleapis.com/git-repo-downloads/repo \
27 > ~/bin/repo && chmod 700 ~/bin/repo
28```
29
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080030Then, modify `~/.zshrc` (or `~/.bash_profile` if using `bash`) to ensure you can
AndroidX Core Team21ccf652022-04-01 14:53:07 +000031find local binaries from the command line. We assume you're using `zsh`, but the
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080032following should work with `bash` as well.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000033
34```shell
35export PATH=~/bin:$PATH
36```
37
AndroidX Core Team693e3f82024-05-17 05:25:53 -070038> NOTE: When using quotes (`"~/bin"`), `~` does not expand and the path is
39> invalid. (Possibly `bash` only?)
40
AndroidX Core Team68274512022-04-28 13:10:15 -070041Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using
42`bash`) aliasing the `repo` command to run with `python3`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +000043
44```shell
45# Force repo to run with Python3
46function repo() {
AndroidX Core Team21ccf652022-04-01 14:53:07 +000047 command python3 ~/bin/repo $@
AndroidX Core Team2e416b22020-12-03 22:58:07 +000048}
49```
50
AndroidX Core Team68274512022-04-28 13:10:15 -070051Finally, you will need to either start a new terminal session or run `source
52~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes.
53
54> NOTE: If you encounter the following warning about Python 2 being no longer
55> supported, you will need to install Python 3 from the
56> [official website](https://www.python.org).
57>
58> ```shell {.bad}
59> repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
60> ```
61
62> NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error:
63>
64> ```shell {.bad}
65> Downloading Repo source from https://gerrit.googlesource.com/git-repo
66> fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
67> fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)
68> ```
69>
AndroidX Core Teamf95fde72024-05-07 11:03:03 -070070> Run the `Install Certificates.command` in the Python folder of Application
71> (e.g. `/Applications/Python\ 3.11/Install\ Certificates.command`). For more
72> information about SSL/TLS certificate validation, you can read the "Important
73> Information" displayed during Python installation.
AndroidX Core Team21ccf652022-04-01 14:53:07 +000074
AndroidX Core Team2e416b22020-12-03 22:58:07 +000075### Windows {#setup-win}
76
77Sorry, Windows is not a supported platform for AndroidX development.
78
79## Set up access control {#access}
80
81### Authenticate to AOSP Gerrit {#access-gerrit}
82
83Before you can upload changes, you will need to associate your Google
84credentials with the AOSP Gerrit code review system by signing in to
85[android-review.googlesource.com](https://android-review.googlesource.com) at
86least once using the account you will use to submit patches.
87
88Next, you will need to
AndroidX Core Team1770ed72024-08-12 10:18:54 -070089[set up authentication](https://android.googlesource.com/new-password).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000090This will give you a shell command to update your local Git cookies, which will
91allow you to upload changes.
92
93Finally, you will need to accept the
94[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
95
96## Check out the source {#source}
97
98Like ChromeOS, Chromium, and the Android build system, we develop in the open as
99much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000100[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000101branch of the Android Open Source Project.
102
AndroidX Core Team1c263a02023-03-30 07:12:19 -0700103As of 2023/03/30, you will need about 42 GB for a fully-built checkout.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000104
105### Synchronize the branch {#source-checkout}
106
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000107Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000108
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500109#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000110
111All development should occur in this branch unless otherwise specified by the
112AndroidX Core team.
113
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000114The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000115
116```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000117mkdir androidx-main && cd androidx-main
alanv7ae48942022-09-27 13:53:32 -0700118repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000119 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000120repo sync -c -j8
121```
122
123NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
124you may need to install Python3 and boot strap the SSL certificates in the
125included version of pip. You can execute `Install Certificates.command` under
126`/Applications/Python 3.6/` to do so.
127
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400128NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
129failed with exit status -6` with cause `md_enable: algorithm 10 not available`
130you may need to install a build of `gpg` that supports SHA512, such as the
131latest version available from [Homebrew](https://brew.sh/) using `brew install
132gpg`.
133
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000134### Increase Git rename limit {#source-config}
135
136To ensure `git` can detect diffs and renames across significant changes (namely,
137the `androidx.*` package rename), we recommend that you set the following `git
138config` properties:
139
140```shell
141git config --global merge.renameLimit 999999
142git config --global diff.renameLimit 999999
143```
144
alanv207674d2022-06-14 11:20:52 -0700145### Set up Git file exclusions {#source-exclude}
146
147Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
148avoid accidentally checking in local metadata files:
149
150```shell
151echo .DS_Store>>~/.gitignore
152git config --global core.excludesFile '~/.gitignore'
153```
154
155### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400156
157The
158[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
159contains a history of the matching exact commits of each git repository over
160time, and it can be
161[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
162
alanve9101e42022-01-28 12:05:11 -0800163### Troubleshooting
164
165> NOTE: If the repo manifest changes -- for example when we update the version
166> of `platform-tools` by pointing it to a different git project -- you may see
167> the following error during`repo sync`:
168>
169> ```shell
170> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
171> ...
172> error: Unable to fully sync the tree.
173> error: Downloading network changes failed.
174> ```
175>
176> This indicates that Studio or some other process has made changes in the git
177> project that has been replaced or removed. You can force `repo sync` to
178> discard these changes and check out the correct git project by adding the
179> `--force-sync` argument:
180>
181> ```shell
182> repo sync -j32 --force-sync
183> ```
184
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000185## Explore source code from a browser {#code-search}
186
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000187`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000188[code search](https://cs.android.com/androidx/platform/frameworks/support) that
189allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000190URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000191
AndroidX Core Team110f54d2022-10-24 08:35:31 -0700192### Custom search engine for `androidx-main` {#custom-search-engine}
193
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000194We recommend setting up a custom search engine in Chrome as a faster (and
195publicly-accessible) alternative to `cs/`.
196
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001971. Open `chrome://settings/searchEngines`
1981. Click the `Add` button
1991. Enter a name for your search engine, ex. "AndroidX Code Search"
2001. Enter a keyword, ex. "csa"
2011. Enter the following URL:
202 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
2031. Click the `Add` button
204
205Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
206query to search for, e.g. `AppCompatButton file:appcompat`, and press the
207`Enter` key to get to the search result page.
208
209## Develop in Android Studio {#studio}
210
211Library development uses a curated version of Android Studio to ensure
212compatibility between various components of the development workflow.
213
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000214From the `frameworks/support` directory, you can use `./studiow m` (short for
215`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400216correct version of Studio to work on the `main` set of androidx projects
217(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000218[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
219also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400220projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000221
222Next, open the `framework/support` project root from your checkout. If Studio
223asks you which SDK you would like to use, select `Use project SDK`. Importing
224projects may take a while, but once that finishes you can use Studio as you
225normally would for application or library development -- right-click on a test
226or sample to run or debug it, search through classes, and so on.
227
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000228> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
229> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
230> opening `File > Project Structure > Platform Settings > SDKs` and manually
231> setting the Android SDK home path to
232> `<project-root>/prebuilts/fullsdk-<platform>`.
233
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500234### Troubleshooting {#studio-troubleshooting}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000235
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500236* If you've updated to macOS Ventura and receive a "xcrun: error: invalid
237 active developer path" message when running Studio, reinstall Xcode using
238 `xcode-select --install`. If that does not work, you will need to download
239 Xcode.
240* If you get a “Unregistered VCS root detected” message, click “Add root” to
241 enable the Git/VCS integration for Android Studio.
242* If you see any errors (red underlines), click Gradle's elephant button in
243 the toolbar (or `File > Sync Project with Gradle Files`) and they should
244 resolve once the build completes.
245* If you run `./studiow` with a new project set but you're still seeing the
246 old project set in `Project`, use `File > Sync Project with Gradle Files` to
247 force a re-sync.
248* If Android Studio's UI looks scaled up, ex. twice the size it should be, you
249 may need to add the following line to your `studio64.vmoptions` file using
250 `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false`
251* If you don't see a specific Gradle task listed in Studio's Gradle pane,
252 check the following:
253 * Studio might be running a different project subset than the one
254 intended. For example, `./studiow main` only loads the `main` set of
255 androidx projects; run `./studiow compose` to load the tasks specific to
256 Compose.
257 * Gradle tasks aren't being loaded. Under Studio's settings =>
258 Experimental, make sure that "Do not build Gradle task list during
259 Gradle sync" is unchecked. Note that unchecking this can reduce Studio's
260 performance.
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700261
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000262If in the future you encounter unexpected errors in Studio and you want to check
263for the possibility it is due to some incorrect settings or other generated
264files, you can run `./studiow --clean main <project subset>` or `./studiow
265--reinstall <project subset>` to clean generated files or reinstall Studio.
266
alanv07cfb5e2022-10-12 11:14:08 -0700267### Enabling Compose `@Preview` annotation previews
AndroidX Core Team6173c652022-05-19 20:43:28 +0000268
alanv07cfb5e2022-10-12 11:14:08 -0700269Add the following dependencies to your project's `build.gradle`:
AndroidX Core Team6173c652022-05-19 20:43:28 +0000270
271```groovy
272dependencies {
273 implementation(project(":compose:ui:ui-tooling-preview"))
274 debugImplementation(project(":compose:ui:ui-tooling"))
275}
276```
277
alanv07cfb5e2022-10-12 11:14:08 -0700278Then,
AndroidX Core Team6173c652022-05-19 20:43:28 +0000279[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
280
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000281## Making changes {#changes}
282
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000283Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000284CL-specific working branches. Use `repo` to create, upload, and abandon local
285branches. Use `git` to manage changes within a local branch.
286
287```shell
288cd path/to/checkout/frameworks/support/
289repo start my_branch_name .
290# make necessary code changes
291# use git to commit changes
292repo upload --cbr -t .
293```
294
295The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000296`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
297can refer to the
298[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
299for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000300
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000301If you see the following prompt, choose `always`:
302
303```
304Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
305```
306
307If the upload succeeds, you'll see an output like:
308
309```
310remote:
311remote: New Changes:
312remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
313remote:
314```
315
316To edit your change, use `git commit --amend`, and re-upload.
317
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000318NOTE If you encounter issues with `repo upload`, consider running upload with
319trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
320logs can be helpful for reporting issues to the team that manages our git
321servers.
322
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000323NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
324skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
325hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
326to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
327
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700328### Fixing Kotlin code style errors
329
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700330`repo upload` automatically runs `ktfmt`, which will cause the upload to fail if
331your code has style errors, which it reports on the command line like so:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700332
333```
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700334[FAILED] ktfmt_hook
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700335 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
336```
337
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700338To find and fix these errors, you can run ktfmt locally, either in a console
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700339window or in the Terminal tool in Android Studio. Running in the Terminal tool
340is preferable because it will surface links to your source files/lines so you
341can easily navigate to the code to fix any problems.
342
343First, to run the tool and see all of the errors, run:
344
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700345`./gradlew module:submodule:ktCheck`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700346
347where module/submodule are the names used to refer to the module you want to
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700348check, such as `navigation:navigation-common`. You can also run ktfmt on the
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700349entire project, but that takes longer as it is checking all active modules in
350your project.
351
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700352Many of the errors that ktfmt finds can be automatically fixed by running
353ktFormat:
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700354
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700355`./gradlew module:submodule:ktFormat`
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700356
AndroidX Core Teamf39d01e2024-06-04 13:43:37 -0700357ktFormat will report any remaining errors, but you can also run `ktCheck` again
358at any time to see an updated list of the remaining errors.
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700359
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000360## Building {#building}
361
362### Modules and Maven artifacts {#modules-and-maven-artifacts}
363
364To build a specific module, use the module's `assemble` Gradle task. For
365example, if you are working on `core` module use:
366
367```shell
368./gradlew core:core:assemble
369```
370
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000371To make warnings fail your build (same as presubmit), use the `--strict` flag,
372which our gradlew expands into a few correctness-related flags including
AndroidX Core Team9d812cd2022-09-01 15:42:06 -0700373`-Pandroidx.validateNoUnrecognizedMessages`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000374
375```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000376./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000377```
378
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500379To build every module and generate the local Maven repository artifact, use the
380`createArchive` Gradle task:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000381
382```shell
383./gradlew createArchive
384```
385
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000386To run the complete build task that our build servers use, use the corresponding
387shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000388
389```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000390./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000391```
392
393### Attaching a debugger to the build
394
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700395Gradle tasks, including building a module, may be run or debugged from within
396Android Studio. To start, you need to add the task as a run configuration: you
397can do this manually by adding the corresponding task by clicking on the run
398configuration dropdown, pressing
399[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
400and adding the corresponding task.
401
402You can also run the task through the IDE from the terminal, by using the
403[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
404feature - type in the task you want to run in the in-IDE terminal, and
405`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
406automatically add the configuration to the run configuration menu - you can then
407cancel the task.
408
409Once the task has been added to the run configuration menu, you can start
410debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000411
412Note that debugging will not be available until Gradle sync has completed.
413
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000414#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000415
416Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000417`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000418
AndroidX Core Team6173c652022-05-19 20:43:28 +00004191. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004201. Click the plus in the top left to create a new "Remote" configuration. Give
421 it a name and hit "Ok".
4221. Set breakpoints.
4231. Run your task with added flags: `./gradlew <your_task_here>
424 -Dorg.gradle.debug=true --no-daemon`
4251. Hit the "Debug" button to the right of the configuration dropdown to attach
426 to the process.
427
428#### Troubleshooting the debugger
429
430If you get a "Connection refused" error, it's likely because a gradle daemon is
431still running on the port specified in the config, and you can fix this by
432killing the running gradle daemons:
433
434```shell
435./gradlew --stop
436```
437
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000438NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000439[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
440
441#### Attaching to an annotation processor
442
443Annotation processors run as part of the build, to debug them is similar to
444debugging the build.
445
446For a Java project:
447
448```shell
449./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
450```
451
452For a Kotlin project:
453
454```shell
455./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"
456```
457
458### Optional: Enabling internal menu in IntelliJ/Studio
459
460To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
461Android Lint checks and Metalava, you can enable the
462[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
463which is typically used for plugin and IDE development.
464
465### Reference documentation {#docs}
466
467Our reference docs (Javadocs and KotlinDocs) are published to
468https://developer.android.com/reference/androidx/packages and may be built
469locally.
470
471NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
472run `./gradlew tasks`
473
AndroidX Core Team76f65452024-01-02 11:39:57 -0800474#### Generate docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700475
476To build API reference docs for both Java and Kotlin source code using Dackka,
477run the Gradle task:
478
479```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500480./gradlew docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700481```
482
483Location of generated refdocs:
484
485* docs-public (what is published to DAC):
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500486 `{androidx-main}/out/androidx/docs-public/build/docs`
487* docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700488
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700489The generated docs are plain HTML pages with links that do not work locally.
490These issues are fixed when the docs are published to DAC, but to preview a
491local version of the docs with functioning links and CSS, run:
492
493```
494python3 development/offlinifyDocs/offlinify_dackka_docs.py
495```
496
497You will need to have the `bs4` Python package installed. The CSS used is not
498the same as what will be used when the docs are published.
499
500By default, this command converts the tip-of-tree docs for all libraries. To see
501more options, run:
502
503```
504python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
505```
506
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000507#### Release docs
508
509To build API reference docs for published artifacts formatted for use on
510[d.android.com](http://d.android.com), run the Gradle command:
511
512```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500513./gradlew zipDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000514```
515
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500516This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This
517command builds docs based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000518`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
519the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000520`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000521colloquially refer to this two step process of (1) updating `docs-public` and
522(2) checking in a prebuilt artifact into the prebuilts directory as
Ian Baker186108e2023-11-20 06:54:36 -0800523[The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™).
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500524So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000525https://developer.android.com/reference/androidx/packages, both of these steps
526need to be completed.
527
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000528### Updating public APIs {#updating-public-apis}
529
530Public API tasks -- including tracking, linting, and verifying compatibility --
531are run under the following conditions based on the `androidx` configuration
532block, evaluated in order:
533
534* `runApiTasks=Yes` => yes
535* `runApiTasks=No` => no
536* `toolingProject=true` => no
537* `mavenVersion` or group version not set => no
538* Has an existing `api/` directory => yes
539* `publish=SNAPSHOT_AND_RELEASE` => yes
540* Otherwise, no
541
542If you make changes to tracked public APIs, you will need to acknowledge the
543changes by updating the `<component>/api/current.txt` and associated API files.
544This is handled automatically by the `updateApi` Gradle task:
545
546```shell
547# Run updateApi for all modules.
548./gradlew updateApi
549
550# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
551./gradlew :appcompat:appcompat-resources:updateApi
552```
553
554If you change the public APIs without updating the API file, your module will
555still build **but** your CL will fail Treehugger presubmit checks.
556
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500557NOTE The `updateApi` task does not generate versioned API files (e.g.
558`1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task
559will always generate `current.txt` API files.
560
alanva5fd21b2021-08-20 10:26:46 -0700561#### What are all these files in `api/`? {#updating-public-apis-glossary}
562
563Historical API surfaces are tracked for compatibility and docs generation
564purposes. For each version -- including `current` to represent the tip-of-tree
565version -- we record three different types of API surfaces.
566
567* `<version>.txt`: Public API surface, tracked for compatibility
568* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
569 compatibility where necessary (see
Ian Baker186108e2023-11-20 06:54:36 -0800570 [Restricted APIs](/docs/api_guidelines/index.md#restricted-api))
alanva5fd21b2021-08-20 10:26:46 -0700571* `public_plus_experimental_<version>.txt`: Public API surface plus
572 `@RequiresOptIn` experimental API surfaces used for documentation (see
Ian Baker186108e2023-11-20 06:54:36 -0800573 [Experimental APIs](/docs/api_guidelines/index.md#experimental-api))
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500574 and API review
alanva5fd21b2021-08-20 10:26:46 -0700575
AndroidX Core Teamf2f418d2024-07-24 11:02:09 -0700576NOTE: Experimental API tracking for KLib is enabled by default for KMP projects
577via parallel `updateAbi` and `checkAbi` tasks. If you have a problem with these
578tools,
579[please file an issue](https://issuetracker.google.com/issues/new?component=1102332&template=1780493).
580As a workaround, you may opt-out by setting
581`enableBinaryCompatibilityValidator = false` under
582`AndroidxMultiplatformExtension` in your library's `build.gradle` file.
583
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000584### Release notes & the `Relnote:` tag {#relnote}
585
586Prior to releasing, release notes are pre-populated using a script and placed
587into a Google Doc. The Google Doc is manually double checked by library owners
588before the release goes live. To auto-populate your release notes, you can use
589the semi-optional commit tag `Relnote:` in your commit, which will automatically
590include that message the commit in the pre-populated release notes.
591
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000592The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000593
594#### How to use it?
595
596One-line release note:
597
598``` {.good}
599Relnote: Fixed a critical bug
600```
601
602``` {.good}
603Relnote: "Fixed a critical bug"
604```
605
606``` {.good}
607Relnote: Added the following string function: `myFoo(\"bar\")`
608```
609
610Multi-line release note:
611
612Note: If the following lines do not contain an indent, you may hit b/165570183.
613
614``` {.good}
615Relnote: "We're launching this awesome new feature! It solves a whole list of
616 problems that require a lot of explaining! "
617```
618
619``` {.good}
620Relnote: """Added the following string function: `myFoo("bar")`
621 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
622 """
623```
624
625Opt out of the Relnote tag:
626
627``` {.good}
628Relnote: N/A
629```
630
631``` {.good}
632Relnote: NA
633```
634
635NOT VALID:
636
637``` {.bad}
638Relnote: This is an INVALID multi-line release note. Our current scripts won't
639include anything beyond the first line. The script has no way of knowing when
640the release note actually stops.
641```
642
643``` {.bad}
644Relnote: This is an INVALID multi-line release note. "Quotes" need to be
645 escaped in order for them to be parsed properly.
646```
647
648### Common build errors
649
650#### Diagnosing build failures
651
652If you've encountered a build failure and you're not sure what is triggering it,
653then please run
654`./development/diagnose-build-failure/diagnose-build-failure.sh`.
655
656This script can categorize your build failure into one of the following
657categories:
658
659* The Gradle Daemon is saving state in memory and triggering a failure
660* Your source files have been changed and/or incompatible git commits have
661 been checked out
662* Some file in the out/ dir is triggering an error
663 * If this happens, diagnose-build-failure.sh should also identify which
664 file(s) specifically
665* The build is nondeterministic and/or affected by timestamps
666* The build via gradlew actually passes and this build failure is specific to
667 Android Studio
668
669Some more-specific build failures are listed below in this page.
670
671#### Out-of-date platform prebuilts
672
673Like a normal Android library developed in Android Studio, libraries within
674`androidx` are built against prebuilts of the platform SDK. These are checked in
675to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
676
677If you are developing against pre-release platform APIs in the internal
678`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
679the latest API changes.
680
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000681#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000682
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800683If Gradle cannot resolve a dependency listed in your `build.gradle`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000684
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800685* You will probably want to import the missing artifact via
686 [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md)
687
688 * We store artifacts in the prebuilts repositories under
689 `prebuilts/androidx` to facilitate reproducible builds even if remote
690 artifacts are changed.
691
692* You may need to [establish trust for](#dependency-verification) the new
693 artifact
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000694
AndroidX Core Teambae52562022-07-06 13:41:40 -0700695##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000696
697Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700698[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
699Update this file to include a constant for the version of the library that you
700want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000701`build.gradle` dependencies.
702
AndroidX Core Teambae52562022-07-06 13:41:40 -0700703**After** you update the `libs.versions.toml` file with new dependencies, you
704can download them by running:
705
706```shell
707cd frameworks/support &&\
708development/importMaven/importMaven.sh import-toml
709```
710
711This command will resolve everything declared in the `libs.versions.toml` file
712and download missing artifacts into `prebuilts/androidx/external` or
713`prebuilts/androidx/internal`.
714
715Make sure to upload these changes before or concurrently (ex. in the same Gerrit
716topic) with the dependent library code.
717
718##### Downloading a dependency without changing `libs.versions.toml`
719
720You can also download a dependency without changing `libs.versions.toml` file by
721directly invoking:
722
723```shell
724cd frameworks/support &&\
725./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
726```
727
728##### Missing konan dependencies
729
730Kotlin Multiplatform projects need prebuilts to compile native code, which are
731located under `prebuilts/androidx/konan`. **After** you update the kotlin
732version of AndroidX, you should also download necessary prebuilts via:
733
734```shell
735cd frameworks/support &&\
736development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
737```
738
739Please remember to commit changes in the `prebuilts/androidx/konan` repository.
740
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000741#### Dependency verification
742
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800743If you import a new dependency that is either unsigned or is signed with a new,
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000744unrecognized key, then you will need to add new dependency verification metadata
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800745to indicate to Gradle that this new dependency is trusted. See the instructions
746[here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000747
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000748#### Updating an existing dependency
749
750If an older version of a dependency prebuilt was already checked in, please
751manually remove it within the same CL that adds the new prebuilt. You will also
752need to update `Dependencies.kt` to reflect the version change.
753
754#### My gradle build fails with "Cannot invoke method getURLs() on null object"
755
756You're using Java 9's javac, possibly because you ran envsetup.sh from the
757platform build or specified Java 9 as the global default Java compiler. For the
758former, you can simply open a new shell and avoid running envsetup.sh. For the
759latter, we recommend you set Java 8 as the default compiler using sudo
760update-java-alternatives; however, if you must use Java 9 as the default then
761you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
762
763#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
764
765You probably need to update the prebuilt SDK used by the gradle build. If you
766are referencing new framework APIs, you will need to wait for the framework
767changes to land in an SDK build (or build it yourself) and then land in both
768prebuilts/fullsdk and prebuilts/sdk. See
Ian Baker186108e2023-11-20 06:54:36 -0800769[Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk)
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500770for more information.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000771
772#### How do I handle refactoring a framework API referenced from a library?
773
774Because AndroidX must compile against both the current framework and the latest
775SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
AndroidX Core Team5ad2f7f2023-01-20 12:26:18 -0500776will need to refactor in stages:
777
7781. Remove references to the target APIs from AndroidX
7792. Perform the refactoring in the framework
7803. Update the framework prebuilt SDK to incorporate changes in (2)
7814. Add references to the refactored APIs in AndroidX
7825. Update AndroidX prebuilts to incorporate changes in (4)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000783
784## Testing {#testing}
785
786AndroidX libraries are expected to include unit or integration test coverage for
787100% of their public API surface. Additionally, all CLs must include a `Test:`
788stanza indicating which tests were used to verify correctness. Any CLs
789implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000790the issue being fixed.
791
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700792### Running tests {#run-tests}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000793
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700794Generally, tests in the AndroidX repository should be run through the Android
795Studio UI. You can also run tests from the command line or via remote devices on
796FTL, see
Ian Baker186108e2023-11-20 06:54:36 -0800797[Running unit and integration tests](/docs/testing.md#running)
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700798for details.
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000799
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700800#### Single test class or method
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000801
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008021. Open the desired test file in Android Studio
8032. Right-click on a test class or `@Test` method name and select `Run <name>`
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000804
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700805#### Full test package
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000806
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008071. In the `Project` side panel, open the desired module
8082. Find the package directory with the tests
8093. Right-click on the directory and select `Run <package>`
810
811### Running sample apps {#run-samples}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000812
813The AndroidX repository has a set of Android applications that exercise AndroidX
814code. These applications can be useful when you want to debug a real running
815application, or reproduce a problem interactively, before writing test code.
816
817These applications are named either `<libraryname>-integration-tests-testapp`,
818or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
819can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000820
Ian Baker186108e2023-11-20 06:54:36 -0800821See the [Testing](/docs/testing.md) page for more resources on
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500822writing, running, and monitoring tests.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000823
824### AVD Manager
825
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000826The Android Studio instance started by `./studiow` uses a custom SDK directory,
827which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700828Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000829unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000830
831You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700832artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000833directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000834
835```shell
836# Using the default MacOS Android SDK directory...
837ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
838 ../../prebuilts/fullsdk-darwin/system-images
839```
840
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000841## Library snapshots {#snapshots}
842
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000843### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000844
845Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000846snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000847
848```groovy {highlight=context:[buildId]}
849allprojects {
850 repositories {
851 google()
852 jcenter()
853 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
854 }
855}
856```
857
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000858You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
859for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000860
861```groovy {highlight=context:SNAPSHOT}
862dependencies {
863 implementation "androidx.core:core:1.2.0-SNAPSHOT"
864}
865```
866
867### Where to find snapshots
868
869If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
870can find them on either our public-facing build server:
871
872`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
873
874or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
875
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700876`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
877build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000878
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700879`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000880
881### Obtaining a build ID
882
883To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000884[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000885on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
886androidx.dev site.
887
888Note that if you are using androidx.dev, you may substitute `latest` for a build
889ID to use the last known good build.
890
891To manually find the last known good `build-id`, you have several options.
892
893#### Snapshots on androidx.dev
894
895[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
896usable builds.
897
898#### Programmatically via `jq`
899
900Install `jq`:
901
902```shell
903sudo apt-get install jq
904```
905
906```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000907ID=`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 +0000908 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
909```
910
911#### Android build server
912
913Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000914[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000915on ci.android.com.
916
917For `androidx-snapshot` target, wait for the green "last known good build"
918button to load and then click it to follow it to the build artifact URL.
919
920### Using in a Gradle build
921
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500922To make these artifacts visible to Gradle, you need to add it as a repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000923
924```groovy
925allprojects {
926 repositories {
927 google()
928 maven {
929 // For all Jetpack libraries (including Compose)
930 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
931 }
932 }
933}
934```
935
936Note that the above requires you to know the `build-id` of the snapshots you
937want.
938
939#### Specifying dependencies
940
941All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
942to use a snapshot artifact, the version in your `build.gradle` will need to be
943updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
944
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500945For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000946following to your `build.gradle`:
947
948```
949dependencies {
950 ...
951 implementation("androidx.core:core:1.2.0-SNAPSHOT")
952 ...
953}
954```
955
956## FAQ {#faq}
957
958### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
959
960If you're working on a new feature or bug fix in AndroidX, you may want to test
961your changes against another project to verify that the change makes sense in a
962real-world context or that a bug's specific repro case has been fixed.
963
964If you need to be absolutely sure that your test will exactly emulate the
965developer's experience, you can repeatedly build the AndroidX archive and
966rebuild your application. In this case, you will need to create a local build of
967AndroidX's local Maven repository artifact and install it in your Android SDK
968path.
969
970First, use the `createArchive` Gradle task to generate the local Maven
971repository artifact:
972
973```shell
AndroidX Core Teamcb7de292024-08-07 14:25:42 -0700974# Creates <path-to-checkout>/out/repository/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000975./gradlew createArchive
976```
977
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700978Using your alternate (non-AndroidX) version of Android Studio open the project's
979`settings.gradle.kts` and add the following within
980`dependencyResolutionManagement` to make your project look for binaries in the
981newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000982
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700983```kotlin
984dependencyResolutionManagement {
985 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000986 repositories {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700987 google()
988 mavenCentral()
989 // Add this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000990 maven {
AndroidX Core Teamcb7de292024-08-07 14:25:42 -0700991 setUrl("<path-to-sdk>/out/repository/")
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000992 }
993 }
994}
995```
996
997NOTE Gradle resolves dependencies in the order that the repositories are defined
998(if 2 repositories can resolve the same dependency, the first listed will do so
999and the second will not). Therefore, if the library you are testing has the same
1000group, artifact, and version as one already published, you will want to list
1001your custom maven repo first.
1002
1003Finally, in the dependencies section of your standalone project's `build.gradle`
1004file, add or update the `implementation` entries to reflect the AndroidX modules
1005that you would like to test. Example:
1006
1007```
1008dependencies {
1009 ...
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001010 implementation "androidx.appcompat:appcompat:1.0.0-alpha02"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001011}
1012```
1013
1014If you are testing your changes in the Android Platform code, you can replace
1015the module you are testing
1016`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1017module. We recommend only replacing the module you are modifying instead of the
1018full m2repository to avoid version issues of other modules. You can either take
1019the unzipped directory from
1020`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
AndroidX Core Teamcb7de292024-08-07 14:25:42 -07001021`<path-to-checkout>/out/repository/` after building `androidx`. Here is an
1022example of replacing the RecyclerView module:
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001023
1024```shell
1025$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1026rm -rf $TARGET;
1027cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1028```
1029
1030Make sure the library versions are the same before and after replacement. Then
1031you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001032
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001033### How do I add content to a library's Overview reference doc page?
1034
1035Put content in a markdown file that ends with `-documentation.md` in the
1036directory that corresponds to the Overview page that you'd like to document.
1037
1038For example, the `androidx.compose.runtime`
1039[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1040includes content from
1041[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 -05001042
1043### How do I enable MultiDex for my library?
1044
AndroidX Core Team5c7f3df2024-06-24 12:06:54 -07001045It is enabled automatically as androidx minSdkVersion is API >=21.