blob: f4e5efa264b94c2b6ce44d25f1e58900c41d14e4 [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 Team68274512022-04-28 13:10:15 -070038Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using
39`bash`) aliasing the `repo` command to run with `python3`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +000040
41```shell
42# Force repo to run with Python3
43function repo() {
AndroidX Core Team21ccf652022-04-01 14:53:07 +000044 command python3 ~/bin/repo $@
AndroidX Core Team2e416b22020-12-03 22:58:07 +000045}
46```
47
AndroidX Core Team68274512022-04-28 13:10:15 -070048Finally, you will need to either start a new terminal session or run `source
49~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes.
50
51> NOTE: If you encounter the following warning about Python 2 being no longer
52> supported, you will need to install Python 3 from the
53> [official website](https://www.python.org).
54>
55> ```shell {.bad}
56> repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
57> ```
58
59> NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error:
60>
61> ```shell {.bad}
62> Downloading Repo source from https://gerrit.googlesource.com/git-repo
63> fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
64> fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)
65> ```
66>
67> Run the `Install Certificates.command` in the Python folder of Application.
68> For more information about SSL/TLS certificate validation, you can read the
69> "Important Information" displayed during Python installation.
AndroidX Core Team21ccf652022-04-01 14:53:07 +000070
AndroidX Core Team2e416b22020-12-03 22:58:07 +000071### Windows {#setup-win}
72
73Sorry, Windows is not a supported platform for AndroidX development.
74
75## Set up access control {#access}
76
77### Authenticate to AOSP Gerrit {#access-gerrit}
78
79Before you can upload changes, you will need to associate your Google
80credentials with the AOSP Gerrit code review system by signing in to
81[android-review.googlesource.com](https://android-review.googlesource.com) at
82least once using the account you will use to submit patches.
83
84Next, you will need to
85[set up authentication](https://android-review.googlesource.com/new-password).
86This will give you a shell command to update your local Git cookies, which will
87allow you to upload changes.
88
89Finally, you will need to accept the
90[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
91
92## Check out the source {#source}
93
94Like ChromeOS, Chromium, and the Android build system, we develop in the open as
95much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +000096[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +000097branch of the Android Open Source Project.
98
AndroidX Core Team1c263a02023-03-30 07:12:19 -070099As of 2023/03/30, you will need about 42 GB for a fully-built checkout.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000100
101### Synchronize the branch {#source-checkout}
102
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000103Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000104
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500105#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000106
107All development should occur in this branch unless otherwise specified by the
108AndroidX Core team.
109
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000110The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000111
112```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000113mkdir androidx-main && cd androidx-main
alanv7ae48942022-09-27 13:53:32 -0700114repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000115 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000116repo sync -c -j8
117```
118
119NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
120you may need to install Python3 and boot strap the SSL certificates in the
121included version of pip. You can execute `Install Certificates.command` under
122`/Applications/Python 3.6/` to do so.
123
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400124NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
125failed with exit status -6` with cause `md_enable: algorithm 10 not available`
126you may need to install a build of `gpg` that supports SHA512, such as the
127latest version available from [Homebrew](https://brew.sh/) using `brew install
128gpg`.
129
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000130### Increase Git rename limit {#source-config}
131
132To ensure `git` can detect diffs and renames across significant changes (namely,
133the `androidx.*` package rename), we recommend that you set the following `git
134config` properties:
135
136```shell
137git config --global merge.renameLimit 999999
138git config --global diff.renameLimit 999999
139```
140
alanv207674d2022-06-14 11:20:52 -0700141### Set up Git file exclusions {#source-exclude}
142
143Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
144avoid accidentally checking in local metadata files:
145
146```shell
147echo .DS_Store>>~/.gitignore
148git config --global core.excludesFile '~/.gitignore'
149```
150
151### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400152
153The
154[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
155contains a history of the matching exact commits of each git repository over
156time, and it can be
157[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
158
alanve9101e42022-01-28 12:05:11 -0800159### Troubleshooting
160
161> NOTE: If the repo manifest changes -- for example when we update the version
162> of `platform-tools` by pointing it to a different git project -- you may see
163> the following error during`repo sync`:
164>
165> ```shell
166> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
167> ...
168> error: Unable to fully sync the tree.
169> error: Downloading network changes failed.
170> ```
171>
172> This indicates that Studio or some other process has made changes in the git
173> project that has been replaced or removed. You can force `repo sync` to
174> discard these changes and check out the correct git project by adding the
175> `--force-sync` argument:
176>
177> ```shell
178> repo sync -j32 --force-sync
179> ```
180
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000181## Explore source code from a browser {#code-search}
182
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000183`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000184[code search](https://cs.android.com/androidx/platform/frameworks/support) that
185allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000186URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000187
AndroidX Core Team110f54d2022-10-24 08:35:31 -0700188### Custom search engine for `androidx-main` {#custom-search-engine}
189
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000190We recommend setting up a custom search engine in Chrome as a faster (and
191publicly-accessible) alternative to `cs/`.
192
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001931. Open `chrome://settings/searchEngines`
1941. Click the `Add` button
1951. Enter a name for your search engine, ex. "AndroidX Code Search"
1961. Enter a keyword, ex. "csa"
1971. Enter the following URL:
198 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
1991. Click the `Add` button
200
201Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
202query to search for, e.g. `AppCompatButton file:appcompat`, and press the
203`Enter` key to get to the search result page.
204
205## Develop in Android Studio {#studio}
206
207Library development uses a curated version of Android Studio to ensure
208compatibility between various components of the development workflow.
209
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000210From the `frameworks/support` directory, you can use `./studiow m` (short for
211`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400212correct version of Studio to work on the `main` set of androidx projects
213(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000214[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
215also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400216projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000217
218Next, open the `framework/support` project root from your checkout. If Studio
219asks you which SDK you would like to use, select `Use project SDK`. Importing
220projects may take a while, but once that finishes you can use Studio as you
221normally would for application or library development -- right-click on a test
222or sample to run or debug it, search through classes, and so on.
223
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000224> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
225> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
226> opening `File > Project Structure > Platform Settings > SDKs` and manually
227> setting the Android SDK home path to
228> `<project-root>/prebuilts/fullsdk-<platform>`.
229
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500230### Troubleshooting {#studio-troubleshooting}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000231
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500232* If you've updated to macOS Ventura and receive a "App is damaged and cannot
233 be opened" message when running Studio, *do not* move the app to the Trash.
234 Cancel out of the dialog and open macOS `System Settings > Gatekeeper`, look
235 for `"Android Studio" was blocked`, and click `Open Anyway` to grant an
236 exception. Alternatively, you can navigate to the Studio `.app` file under
237 `frameworks/support/studio` and run it once using `Control+Click` and `Open`
238 to automatically grant an exception.
239* If you've updated to macOS Ventura and receive a "xcrun: error: invalid
240 active developer path" message when running Studio, reinstall Xcode using
241 `xcode-select --install`. If that does not work, you will need to download
242 Xcode.
243* If you get a “Unregistered VCS root detected” message, click “Add root” to
244 enable the Git/VCS integration for Android Studio.
245* If you see any errors (red underlines), click Gradle's elephant button in
246 the toolbar (or `File > Sync Project with Gradle Files`) and they should
247 resolve once the build completes.
248* If you run `./studiow` with a new project set but you're still seeing the
249 old project set in `Project`, use `File > Sync Project with Gradle Files` to
250 force a re-sync.
251* If Android Studio's UI looks scaled up, ex. twice the size it should be, you
252 may need to add the following line to your `studio64.vmoptions` file using
253 `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false`
254* If you don't see a specific Gradle task listed in Studio's Gradle pane,
255 check the following:
256 * Studio might be running a different project subset than the one
257 intended. For example, `./studiow main` only loads the `main` set of
258 androidx projects; run `./studiow compose` to load the tasks specific to
259 Compose.
260 * Gradle tasks aren't being loaded. Under Studio's settings =>
261 Experimental, make sure that "Do not build Gradle task list during
262 Gradle sync" is unchecked. Note that unchecking this can reduce Studio's
263 performance.
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700264
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000265If in the future you encounter unexpected errors in Studio and you want to check
266for the possibility it is due to some incorrect settings or other generated
267files, you can run `./studiow --clean main <project subset>` or `./studiow
268--reinstall <project subset>` to clean generated files or reinstall Studio.
269
alanv07cfb5e2022-10-12 11:14:08 -0700270### Enabling Compose `@Preview` annotation previews
AndroidX Core Team6173c652022-05-19 20:43:28 +0000271
alanv07cfb5e2022-10-12 11:14:08 -0700272Add the following dependencies to your project's `build.gradle`:
AndroidX Core Team6173c652022-05-19 20:43:28 +0000273
274```groovy
275dependencies {
276 implementation(project(":compose:ui:ui-tooling-preview"))
277 debugImplementation(project(":compose:ui:ui-tooling"))
278}
279```
280
alanv07cfb5e2022-10-12 11:14:08 -0700281Then,
AndroidX Core Team6173c652022-05-19 20:43:28 +0000282[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
283
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000284## Making changes {#changes}
285
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000286Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000287CL-specific working branches. Use `repo` to create, upload, and abandon local
288branches. Use `git` to manage changes within a local branch.
289
290```shell
291cd path/to/checkout/frameworks/support/
292repo start my_branch_name .
293# make necessary code changes
294# use git to commit changes
295repo upload --cbr -t .
296```
297
298The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000299`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
300can refer to the
301[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
302for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000303
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000304If you see the following prompt, choose `always`:
305
306```
307Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
308```
309
310If the upload succeeds, you'll see an output like:
311
312```
313remote:
314remote: New Changes:
315remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
316remote:
317```
318
319To edit your change, use `git commit --amend`, and re-upload.
320
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000321NOTE If you encounter issues with `repo upload`, consider running upload with
322trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
323logs can be helpful for reporting issues to the team that manages our git
324servers.
325
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000326NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
327skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
328hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
329to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
330
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700331### Fixing Kotlin code style errors
332
333`repo upload` automatically runs `ktlint`, which will cause the upload to fail
334if your code has style errors, which it reports on the command line like so:
335
336```
337[FAILED] ktlint_hook
338 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
339```
340
341To find and fix these errors, you can run ktlint locally, either in a console
342window or in the Terminal tool in Android Studio. Running in the Terminal tool
343is preferable because it will surface links to your source files/lines so you
344can easily navigate to the code to fix any problems.
345
346First, to run the tool and see all of the errors, run:
347
348`./gradlew module:submodule:ktlint`
349
350where module/submodule are the names used to refer to the module you want to
351check, such as `navigation:navigation-common`. You can also run ktlint on the
352entire project, but that takes longer as it is checking all active modules in
353your project.
354
355Many of the errors that ktlint finds can be automatically fixed by running
356ktlintFormat:
357
358`./gradlew module:submodule:ktlintFormat`
359
360ktlintFormat will report any remaining errors, but you can also run `ktlint`
361again at any time to see an updated list of the remaining errors.
362
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000363## Building {#building}
364
365### Modules and Maven artifacts {#modules-and-maven-artifacts}
366
367To build a specific module, use the module's `assemble` Gradle task. For
368example, if you are working on `core` module use:
369
370```shell
371./gradlew core:core:assemble
372```
373
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000374To make warnings fail your build (same as presubmit), use the `--strict` flag,
375which our gradlew expands into a few correctness-related flags including
AndroidX Core Team9d812cd2022-09-01 15:42:06 -0700376`-Pandroidx.validateNoUnrecognizedMessages`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000377
378```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000379./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000380```
381
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500382To build every module and generate the local Maven repository artifact, use the
383`createArchive` Gradle task:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000384
385```shell
386./gradlew createArchive
387```
388
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000389To run the complete build task that our build servers use, use the corresponding
390shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000391
392```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000393./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000394```
395
396### Attaching a debugger to the build
397
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700398Gradle tasks, including building a module, may be run or debugged from within
399Android Studio. To start, you need to add the task as a run configuration: you
400can do this manually by adding the corresponding task by clicking on the run
401configuration dropdown, pressing
402[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
403and adding the corresponding task.
404
405You can also run the task through the IDE from the terminal, by using the
406[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
407feature - type in the task you want to run in the in-IDE terminal, and
408`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
409automatically add the configuration to the run configuration menu - you can then
410cancel the task.
411
412Once the task has been added to the run configuration menu, you can start
413debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000414
415Note that debugging will not be available until Gradle sync has completed.
416
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000417#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000418
419Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000420`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000421
AndroidX Core Team6173c652022-05-19 20:43:28 +00004221. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004231. Click the plus in the top left to create a new "Remote" configuration. Give
424 it a name and hit "Ok".
4251. Set breakpoints.
4261. Run your task with added flags: `./gradlew <your_task_here>
427 -Dorg.gradle.debug=true --no-daemon`
4281. Hit the "Debug" button to the right of the configuration dropdown to attach
429 to the process.
430
431#### Troubleshooting the debugger
432
433If you get a "Connection refused" error, it's likely because a gradle daemon is
434still running on the port specified in the config, and you can fix this by
435killing the running gradle daemons:
436
437```shell
438./gradlew --stop
439```
440
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000441NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000442[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
443
444#### Attaching to an annotation processor
445
446Annotation processors run as part of the build, to debug them is similar to
447debugging the build.
448
449For a Java project:
450
451```shell
452./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
453```
454
455For a Kotlin project:
456
457```shell
458./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"
459```
460
461### Optional: Enabling internal menu in IntelliJ/Studio
462
463To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
464Android Lint checks and Metalava, you can enable the
465[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
466which is typically used for plugin and IDE development.
467
468### Reference documentation {#docs}
469
470Our reference docs (Javadocs and KotlinDocs) are published to
471https://developer.android.com/reference/androidx/packages and may be built
472locally.
473
474NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
475run `./gradlew tasks`
476
AndroidX Core Team76f65452024-01-02 11:39:57 -0800477#### Generate docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700478
479To build API reference docs for both Java and Kotlin source code using Dackka,
480run the Gradle task:
481
482```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500483./gradlew docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700484```
485
486Location of generated refdocs:
487
488* docs-public (what is published to DAC):
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500489 `{androidx-main}/out/androidx/docs-public/build/docs`
490* docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700491
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700492The generated docs are plain HTML pages with links that do not work locally.
493These issues are fixed when the docs are published to DAC, but to preview a
494local version of the docs with functioning links and CSS, run:
495
496```
497python3 development/offlinifyDocs/offlinify_dackka_docs.py
498```
499
500You will need to have the `bs4` Python package installed. The CSS used is not
501the same as what will be used when the docs are published.
502
503By default, this command converts the tip-of-tree docs for all libraries. To see
504more options, run:
505
506```
507python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
508```
509
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000510#### Release docs
511
512To build API reference docs for published artifacts formatted for use on
513[d.android.com](http://d.android.com), run the Gradle command:
514
515```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500516./gradlew zipDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000517```
518
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500519This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This
520command builds docs based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000521`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
522the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000523`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000524colloquially refer to this two step process of (1) updating `docs-public` and
525(2) checking in a prebuilt artifact into the prebuilts directory as
Ian Baker186108e2023-11-20 06:54:36 -0800526[The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™).
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500527So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000528https://developer.android.com/reference/androidx/packages, both of these steps
529need to be completed.
530
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000531### Updating public APIs {#updating-public-apis}
532
533Public API tasks -- including tracking, linting, and verifying compatibility --
534are run under the following conditions based on the `androidx` configuration
535block, evaluated in order:
536
537* `runApiTasks=Yes` => yes
538* `runApiTasks=No` => no
539* `toolingProject=true` => no
540* `mavenVersion` or group version not set => no
541* Has an existing `api/` directory => yes
542* `publish=SNAPSHOT_AND_RELEASE` => yes
543* Otherwise, no
544
545If you make changes to tracked public APIs, you will need to acknowledge the
546changes by updating the `<component>/api/current.txt` and associated API files.
547This is handled automatically by the `updateApi` Gradle task:
548
549```shell
550# Run updateApi for all modules.
551./gradlew updateApi
552
553# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
554./gradlew :appcompat:appcompat-resources:updateApi
555```
556
557If you change the public APIs without updating the API file, your module will
558still build **but** your CL will fail Treehugger presubmit checks.
559
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500560NOTE The `updateApi` task does not generate versioned API files (e.g.
561`1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task
562will always generate `current.txt` API files.
563
alanva5fd21b2021-08-20 10:26:46 -0700564#### What are all these files in `api/`? {#updating-public-apis-glossary}
565
566Historical API surfaces are tracked for compatibility and docs generation
567purposes. For each version -- including `current` to represent the tip-of-tree
568version -- we record three different types of API surfaces.
569
570* `<version>.txt`: Public API surface, tracked for compatibility
571* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
572 compatibility where necessary (see
Ian Baker186108e2023-11-20 06:54:36 -0800573 [Restricted APIs](/docs/api_guidelines/index.md#restricted-api))
alanva5fd21b2021-08-20 10:26:46 -0700574* `public_plus_experimental_<version>.txt`: Public API surface plus
575 `@RequiresOptIn` experimental API surfaces used for documentation (see
Ian Baker186108e2023-11-20 06:54:36 -0800576 [Experimental APIs](/docs/api_guidelines/index.md#experimental-api))
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500577 and API review
alanva5fd21b2021-08-20 10:26:46 -0700578
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000579### Release notes & the `Relnote:` tag {#relnote}
580
581Prior to releasing, release notes are pre-populated using a script and placed
582into a Google Doc. The Google Doc is manually double checked by library owners
583before the release goes live. To auto-populate your release notes, you can use
584the semi-optional commit tag `Relnote:` in your commit, which will automatically
585include that message the commit in the pre-populated release notes.
586
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000587The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000588
589#### How to use it?
590
591One-line release note:
592
593``` {.good}
594Relnote: Fixed a critical bug
595```
596
597``` {.good}
598Relnote: "Fixed a critical bug"
599```
600
601``` {.good}
602Relnote: Added the following string function: `myFoo(\"bar\")`
603```
604
605Multi-line release note:
606
607Note: If the following lines do not contain an indent, you may hit b/165570183.
608
609``` {.good}
610Relnote: "We're launching this awesome new feature! It solves a whole list of
611 problems that require a lot of explaining! "
612```
613
614``` {.good}
615Relnote: """Added the following string function: `myFoo("bar")`
616 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
617 """
618```
619
620Opt out of the Relnote tag:
621
622``` {.good}
623Relnote: N/A
624```
625
626``` {.good}
627Relnote: NA
628```
629
630NOT VALID:
631
632``` {.bad}
633Relnote: This is an INVALID multi-line release note. Our current scripts won't
634include anything beyond the first line. The script has no way of knowing when
635the release note actually stops.
636```
637
638``` {.bad}
639Relnote: This is an INVALID multi-line release note. "Quotes" need to be
640 escaped in order for them to be parsed properly.
641```
642
643### Common build errors
644
645#### Diagnosing build failures
646
647If you've encountered a build failure and you're not sure what is triggering it,
648then please run
649`./development/diagnose-build-failure/diagnose-build-failure.sh`.
650
651This script can categorize your build failure into one of the following
652categories:
653
654* The Gradle Daemon is saving state in memory and triggering a failure
655* Your source files have been changed and/or incompatible git commits have
656 been checked out
657* Some file in the out/ dir is triggering an error
658 * If this happens, diagnose-build-failure.sh should also identify which
659 file(s) specifically
660* The build is nondeterministic and/or affected by timestamps
661* The build via gradlew actually passes and this build failure is specific to
662 Android Studio
663
664Some more-specific build failures are listed below in this page.
665
666#### Out-of-date platform prebuilts
667
668Like a normal Android library developed in Android Studio, libraries within
669`androidx` are built against prebuilts of the platform SDK. These are checked in
670to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
671
672If you are developing against pre-release platform APIs in the internal
673`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
674the latest API changes.
675
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000676#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000677
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800678If Gradle cannot resolve a dependency listed in your `build.gradle`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000679
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800680* You will probably want to import the missing artifact via
681 [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md)
682
683 * We store artifacts in the prebuilts repositories under
684 `prebuilts/androidx` to facilitate reproducible builds even if remote
685 artifacts are changed.
686
687* You may need to [establish trust for](#dependency-verification) the new
688 artifact
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000689
AndroidX Core Teambae52562022-07-06 13:41:40 -0700690##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000691
692Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700693[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
694Update this file to include a constant for the version of the library that you
695want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000696`build.gradle` dependencies.
697
AndroidX Core Teambae52562022-07-06 13:41:40 -0700698**After** you update the `libs.versions.toml` file with new dependencies, you
699can download them by running:
700
701```shell
702cd frameworks/support &&\
703development/importMaven/importMaven.sh import-toml
704```
705
706This command will resolve everything declared in the `libs.versions.toml` file
707and download missing artifacts into `prebuilts/androidx/external` or
708`prebuilts/androidx/internal`.
709
710Make sure to upload these changes before or concurrently (ex. in the same Gerrit
711topic) with the dependent library code.
712
713##### Downloading a dependency without changing `libs.versions.toml`
714
715You can also download a dependency without changing `libs.versions.toml` file by
716directly invoking:
717
718```shell
719cd frameworks/support &&\
720./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
721```
722
723##### Missing konan dependencies
724
725Kotlin Multiplatform projects need prebuilts to compile native code, which are
726located under `prebuilts/androidx/konan`. **After** you update the kotlin
727version of AndroidX, you should also download necessary prebuilts via:
728
729```shell
730cd frameworks/support &&\
731development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
732```
733
734Please remember to commit changes in the `prebuilts/androidx/konan` repository.
735
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000736#### Dependency verification
737
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800738If you import a new dependency that is either unsigned or is signed with a new,
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000739unrecognized key, then you will need to add new dependency verification metadata
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800740to indicate to Gradle that this new dependency is trusted. See the instructions
741[here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000742
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000743#### Updating an existing dependency
744
745If an older version of a dependency prebuilt was already checked in, please
746manually remove it within the same CL that adds the new prebuilt. You will also
747need to update `Dependencies.kt` to reflect the version change.
748
749#### My gradle build fails with "Cannot invoke method getURLs() on null object"
750
751You're using Java 9's javac, possibly because you ran envsetup.sh from the
752platform build or specified Java 9 as the global default Java compiler. For the
753former, you can simply open a new shell and avoid running envsetup.sh. For the
754latter, we recommend you set Java 8 as the default compiler using sudo
755update-java-alternatives; however, if you must use Java 9 as the default then
756you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
757
758#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
759
760You probably need to update the prebuilt SDK used by the gradle build. If you
761are referencing new framework APIs, you will need to wait for the framework
762changes to land in an SDK build (or build it yourself) and then land in both
763prebuilts/fullsdk and prebuilts/sdk. See
Ian Baker186108e2023-11-20 06:54:36 -0800764[Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk)
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500765for more information.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000766
767#### How do I handle refactoring a framework API referenced from a library?
768
769Because AndroidX must compile against both the current framework and the latest
770SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
AndroidX Core Team5ad2f7f2023-01-20 12:26:18 -0500771will need to refactor in stages:
772
7731. Remove references to the target APIs from AndroidX
7742. Perform the refactoring in the framework
7753. Update the framework prebuilt SDK to incorporate changes in (2)
7764. Add references to the refactored APIs in AndroidX
7775. Update AndroidX prebuilts to incorporate changes in (4)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000778
779## Testing {#testing}
780
781AndroidX libraries are expected to include unit or integration test coverage for
782100% of their public API surface. Additionally, all CLs must include a `Test:`
783stanza indicating which tests were used to verify correctness. Any CLs
784implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000785the issue being fixed.
786
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700787### Running tests {#run-tests}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000788
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700789Generally, tests in the AndroidX repository should be run through the Android
790Studio UI. You can also run tests from the command line or via remote devices on
791FTL, see
Ian Baker186108e2023-11-20 06:54:36 -0800792[Running unit and integration tests](/docs/testing.md#running)
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700793for details.
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000794
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700795#### Single test class or method
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000796
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07007971. Open the desired test file in Android Studio
7982. Right-click on a test class or `@Test` method name and select `Run <name>`
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000799
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700800#### Full test package
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000801
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008021. In the `Project` side panel, open the desired module
8032. Find the package directory with the tests
8043. Right-click on the directory and select `Run <package>`
805
806### Running sample apps {#run-samples}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000807
808The AndroidX repository has a set of Android applications that exercise AndroidX
809code. These applications can be useful when you want to debug a real running
810application, or reproduce a problem interactively, before writing test code.
811
812These applications are named either `<libraryname>-integration-tests-testapp`,
813or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
814can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000815
Ian Baker186108e2023-11-20 06:54:36 -0800816See the [Testing](/docs/testing.md) page for more resources on
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500817writing, running, and monitoring tests.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000818
819### AVD Manager
820
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000821The Android Studio instance started by `./studiow` uses a custom SDK directory,
822which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700823Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000824unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000825
826You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700827artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000828directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000829
830```shell
831# Using the default MacOS Android SDK directory...
832ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
833 ../../prebuilts/fullsdk-darwin/system-images
834```
835
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000836## Library snapshots {#snapshots}
837
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000838### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000839
840Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000841snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000842
843```groovy {highlight=context:[buildId]}
844allprojects {
845 repositories {
846 google()
847 jcenter()
848 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
849 }
850}
851```
852
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000853You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
854for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000855
856```groovy {highlight=context:SNAPSHOT}
857dependencies {
858 implementation "androidx.core:core:1.2.0-SNAPSHOT"
859}
860```
861
862### Where to find snapshots
863
864If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
865can find them on either our public-facing build server:
866
867`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
868
869or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
870
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700871`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
872build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000873
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700874`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000875
876### Obtaining a build ID
877
878To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000879[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000880on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
881androidx.dev site.
882
883Note that if you are using androidx.dev, you may substitute `latest` for a build
884ID to use the last known good build.
885
886To manually find the last known good `build-id`, you have several options.
887
888#### Snapshots on androidx.dev
889
890[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
891usable builds.
892
893#### Programmatically via `jq`
894
895Install `jq`:
896
897```shell
898sudo apt-get install jq
899```
900
901```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000902ID=`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 +0000903 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
904```
905
906#### Android build server
907
908Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000909[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000910on ci.android.com.
911
912For `androidx-snapshot` target, wait for the green "last known good build"
913button to load and then click it to follow it to the build artifact URL.
914
915### Using in a Gradle build
916
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500917To make these artifacts visible to Gradle, you need to add it as a repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000918
919```groovy
920allprojects {
921 repositories {
922 google()
923 maven {
924 // For all Jetpack libraries (including Compose)
925 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
926 }
927 }
928}
929```
930
931Note that the above requires you to know the `build-id` of the snapshots you
932want.
933
934#### Specifying dependencies
935
936All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
937to use a snapshot artifact, the version in your `build.gradle` will need to be
938updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
939
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500940For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000941following to your `build.gradle`:
942
943```
944dependencies {
945 ...
946 implementation("androidx.core:core:1.2.0-SNAPSHOT")
947 ...
948}
949```
950
951## FAQ {#faq}
952
953### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
954
955If you're working on a new feature or bug fix in AndroidX, you may want to test
956your changes against another project to verify that the change makes sense in a
957real-world context or that a bug's specific repro case has been fixed.
958
959If you need to be absolutely sure that your test will exactly emulate the
960developer's experience, you can repeatedly build the AndroidX archive and
961rebuild your application. In this case, you will need to create a local build of
962AndroidX's local Maven repository artifact and install it in your Android SDK
963path.
964
965First, use the `createArchive` Gradle task to generate the local Maven
966repository artifact:
967
968```shell
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000969# Creates <path-to-checkout>/out/androidx/build/support_repo/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000970./gradlew createArchive
971```
972
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700973Using your alternate (non-AndroidX) version of Android Studio open the project's
974`settings.gradle.kts` and add the following within
975`dependencyResolutionManagement` to make your project look for binaries in the
976newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000977
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700978```kotlin
979dependencyResolutionManagement {
980 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000981 repositories {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700982 google()
983 mavenCentral()
984 // Add this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000985 maven {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700986 setUrl("<path-to-sdk>/out/androidx/build/support_repo/")
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000987 }
988 }
989}
990```
991
992NOTE Gradle resolves dependencies in the order that the repositories are defined
993(if 2 repositories can resolve the same dependency, the first listed will do so
994and the second will not). Therefore, if the library you are testing has the same
995group, artifact, and version as one already published, you will want to list
996your custom maven repo first.
997
998Finally, in the dependencies section of your standalone project's `build.gradle`
999file, add or update the `implementation` entries to reflect the AndroidX modules
1000that you would like to test. Example:
1001
1002```
1003dependencies {
1004 ...
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001005 implementation "androidx.appcompat:appcompat:1.0.0-alpha02"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001006}
1007```
1008
1009If you are testing your changes in the Android Platform code, you can replace
1010the module you are testing
1011`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1012module. We recommend only replacing the module you are modifying instead of the
1013full m2repository to avoid version issues of other modules. You can either take
1014the unzipped directory from
1015`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001016`<path-to-checkout>/out/androidx/build/support_repo/` after building `androidx`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001017Here is an example of replacing the RecyclerView module:
1018
1019```shell
1020$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1021rm -rf $TARGET;
1022cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1023```
1024
1025Make sure the library versions are the same before and after replacement. Then
1026you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001027
1028### How do I measure library size? {#library-size}
1029
1030Method count and bytecode size are tracked in CI
Ian Baker186108e2023-11-20 06:54:36 -08001031[alongside benchmarks](/docs/benchmarking.md#monitoring) to
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001032detect regressions.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001033
1034For local measurements, use the `:reportLibraryMetrics` task. For example:
1035
1036```shell
1037./gradlew benchmark:benchmark-macro:reportLibraryMetrics
1038cat ../../out/dist/librarymetrics/androidx.benchmark_benchmark-macro.json
1039```
1040
1041Will output something like: `{"method_count":1256,"bytecode_size":178822}`
1042
1043Note: this only counts the weight of your library's jar/aar, including
1044resources. It does not count library dependencies. It does not account for a
1045minification step (e.g. with R8), as that is dynamic, and done at app build time
1046(and depend on which entrypoints the app uses).
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001047
1048### How do I add content to a library's Overview reference doc page?
1049
1050Put content in a markdown file that ends with `-documentation.md` in the
1051directory that corresponds to the Overview page that you'd like to document.
1052
1053For example, the `androidx.compose.runtime`
1054[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1055includes content from
1056[compose-runtime-documentation.md](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/compose-runtime-documentation.md).
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001057
1058### How do I enable MultiDex for my library?
1059
1060Go to your project/app level build.gradle file, and add
1061
1062```
1063android {
1064 defaultConfig {
1065 multiDexEnabled = true
1066 }
1067}
1068```
1069
1070as well as `androidTestImplementation(libs.multidex)` to the dependenices block.
1071
AndroidX Core Team76f65452024-01-02 11:39:57 -08001072If you want it enabled for the application and not test APK, add
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001073`implementation(libs.multidex)` to the dependencies block instead. Any prior
1074failures may not re-occur now that the software is multi-dexed. Rerun the build.