blob: 7fd3c15ef585b29829b977d8db8bbbf97bccb34c [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
9see [Life of a Jetpack Feature](loaf.md) for details on developing and releasing
10a library, [API Guidelines](api_guidelines.md) for best practices regarding
AndroidX Core Team9e6c2362021-08-30 12:22:59 -070011public APIs and an overview of the constraints placed on changes.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000012
13## Workstation setup {#setup}
14
AndroidX Core Teamcc1e9b12022-06-27 13:10:24 -070015This section will help you install the `repo` tool, which is used for Git branch
16and commit management. If you want to learn more about `repo`, see the
17[Repo Command Reference](https://source.android.com/setup/develop/repo).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000018
19### Linux and MacOS {#setup-linux-mac}
20
21First, download `repo` using `curl`.
22
23```shell
24test -d ~/bin || mkdir ~/bin
25curl https://storage.googleapis.com/git-repo-downloads/repo \
26 > ~/bin/repo && chmod 700 ~/bin/repo
27```
28
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080029Then, modify `~/.zshrc` (or `~/.bash_profile` if using `bash`) to ensure you can
AndroidX Core Team21ccf652022-04-01 14:53:07 +000030find local binaries from the command line. We assume you're using `zsh`, but the
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080031following should work with `bash` as well.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000032
33```shell
34export PATH=~/bin:$PATH
35```
36
AndroidX Core Team68274512022-04-28 13:10:15 -070037Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using
38`bash`) aliasing the `repo` command to run with `python3`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +000039
40```shell
41# Force repo to run with Python3
42function repo() {
AndroidX Core Team21ccf652022-04-01 14:53:07 +000043 command python3 ~/bin/repo $@
AndroidX Core Team2e416b22020-12-03 22:58:07 +000044}
45```
46
AndroidX Core Team68274512022-04-28 13:10:15 -070047Finally, you will need to either start a new terminal session or run `source
48~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes.
49
50> NOTE: If you encounter the following warning about Python 2 being no longer
51> supported, you will need to install Python 3 from the
52> [official website](https://www.python.org).
53>
54> ```shell {.bad}
55> repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
56> ```
57
58> NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error:
59>
60> ```shell {.bad}
61> Downloading Repo source from https://gerrit.googlesource.com/git-repo
62> fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
63> fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)
64> ```
65>
66> Run the `Install Certificates.command` in the Python folder of Application.
67> For more information about SSL/TLS certificate validation, you can read the
68> "Important Information" displayed during Python installation.
AndroidX Core Team21ccf652022-04-01 14:53:07 +000069
AndroidX Core Team2e416b22020-12-03 22:58:07 +000070### Windows {#setup-win}
71
72Sorry, Windows is not a supported platform for AndroidX development.
73
74## Set up access control {#access}
75
76### Authenticate to AOSP Gerrit {#access-gerrit}
77
78Before you can upload changes, you will need to associate your Google
79credentials with the AOSP Gerrit code review system by signing in to
80[android-review.googlesource.com](https://android-review.googlesource.com) at
81least once using the account you will use to submit patches.
82
83Next, you will need to
84[set up authentication](https://android-review.googlesource.com/new-password).
85This will give you a shell command to update your local Git cookies, which will
86allow you to upload changes.
87
88Finally, you will need to accept the
89[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
90
91## Check out the source {#source}
92
93Like ChromeOS, Chromium, and the Android build system, we develop in the open as
94much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +000095[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +000096branch of the Android Open Source Project.
97
98As of 2020/03/20, you will need about 38 GB for a fully-built checkout.
99
100### Synchronize the branch {#source-checkout}
101
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000102Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000103
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500104#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000105
106All development should occur in this branch unless otherwise specified by the
107AndroidX Core team.
108
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000109The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000110
111```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000112mkdir androidx-main && cd androidx-main
alanv449e20a2022-07-11 13:39:32 -0700113repo init -u sso://android/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000114 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000115repo sync -c -j8
116```
117
118NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
119you may need to install Python3 and boot strap the SSL certificates in the
120included version of pip. You can execute `Install Certificates.command` under
121`/Applications/Python 3.6/` to do so.
122
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400123NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
124failed with exit status -6` with cause `md_enable: algorithm 10 not available`
125you may need to install a build of `gpg` that supports SHA512, such as the
126latest version available from [Homebrew](https://brew.sh/) using `brew install
127gpg`.
128
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000129### Increase Git rename limit {#source-config}
130
131To ensure `git` can detect diffs and renames across significant changes (namely,
132the `androidx.*` package rename), we recommend that you set the following `git
133config` properties:
134
135```shell
136git config --global merge.renameLimit 999999
137git config --global diff.renameLimit 999999
138```
139
alanv207674d2022-06-14 11:20:52 -0700140### Set up Git file exclusions {#source-exclude}
141
142Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
143avoid accidentally checking in local metadata files:
144
145```shell
146echo .DS_Store>>~/.gitignore
147git config --global core.excludesFile '~/.gitignore'
148```
149
150### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400151
152The
153[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
154contains a history of the matching exact commits of each git repository over
155time, and it can be
156[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
157
alanve9101e42022-01-28 12:05:11 -0800158### Troubleshooting
159
160> NOTE: If the repo manifest changes -- for example when we update the version
161> of `platform-tools` by pointing it to a different git project -- you may see
162> the following error during`repo sync`:
163>
164> ```shell
165> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
166> ...
167> error: Unable to fully sync the tree.
168> error: Downloading network changes failed.
169> ```
170>
171> This indicates that Studio or some other process has made changes in the git
172> project that has been replaced or removed. You can force `repo sync` to
173> discard these changes and check out the correct git project by adding the
174> `--force-sync` argument:
175>
176> ```shell
177> repo sync -j32 --force-sync
178> ```
179
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000180## Explore source code from a browser {#code-search}
181
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000182`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000183[code search](https://cs.android.com/androidx/platform/frameworks/support) that
184allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000185URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000186
187We recommend setting up a custom search engine in Chrome as a faster (and
188publicly-accessible) alternative to `cs/`.
189
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000190### Custom search engine for `androidx-main` {#custom-search-engine}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000191
1921. Open `chrome://settings/searchEngines`
1931. Click the `Add` button
1941. Enter a name for your search engine, ex. "AndroidX Code Search"
1951. Enter a keyword, ex. "csa"
1961. Enter the following URL:
197 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
1981. Click the `Add` button
199
200Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
201query to search for, e.g. `AppCompatButton file:appcompat`, and press the
202`Enter` key to get to the search result page.
203
204## Develop in Android Studio {#studio}
205
206Library development uses a curated version of Android Studio to ensure
207compatibility between various components of the development workflow.
208
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000209From the `frameworks/support` directory, you can use `./studiow m` (short for
210`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400211correct version of Studio to work on the `main` set of androidx projects
212(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000213[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
214also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400215projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000216
217Next, open the `framework/support` project root from your checkout. If Studio
218asks you which SDK you would like to use, select `Use project SDK`. Importing
219projects may take a while, but once that finishes you can use Studio as you
220normally would for application or library development -- right-click on a test
221or sample to run or debug it, search through classes, and so on.
222
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000223If you get a “Unregistered VCS root detected” message, click “Add root” to
224enable the Git/VCS integration for Android Studio.
225
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000226If you see any errors (red underlines), click Gradle's elephant button in the
227toolbar ("Sync Project with Gradle Files") and they should resolve once the
228build completes.
229
230> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
231> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
232> opening `File > Project Structure > Platform Settings > SDKs` and manually
233> setting the Android SDK home path to
234> `<project-root>/prebuilts/fullsdk-<platform>`.
235
236> NOTE: If Android Studio's UI looks scaled up, ex. twice the size it should be,
237> you may need to add the following line to your `studio64.vmoptions` file using
238> `Help -> Edit Custom VM Options`:
239>
240> ```
241> -Dsun.java2d.uiScale.enabled=false
242> ```
243
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700244> NOTE: We are aware of a bug where running `./studiow` does not result in
245> Android Studio application being launched.
246
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000247If in the future you encounter unexpected errors in Studio and you want to check
248for the possibility it is due to some incorrect settings or other generated
249files, you can run `./studiow --clean main <project subset>` or `./studiow
250--reinstall <project subset>` to clean generated files or reinstall Studio.
251
AndroidX Core Teame80aab72021-09-29 08:44:33 -0700252> Tip: If you don't see a specific Gradle task listed in Studio's Gradle pane,
253> check the following:
254>
255> * Studio might be running a different project subset than the one intended.
256> For example, `./studiow main` only loads the `main` set of androidx
257> projects; run `./studiow compose` to load the tasks specific to Compose.
258>
259> * Gradle tasks aren't being loaded. Under Studio's settings => Experimental,
260> make sure that "Do not build Gradle task list during Gradle sync" is
261> unchecked. (Note that unchecking this can reduce Studio's performance)
262
AndroidX Core Team6173c652022-05-19 20:43:28 +0000263### Enabling Compose @Preview annotation previews
264
265Add the following dependencies to your project's `build.gradle`
266
267```groovy
268dependencies {
269 implementation(project(":compose:ui:ui-tooling-preview"))
270 debugImplementation(project(":compose:ui:ui-tooling"))
271}
272```
273
274then
275[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
276
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000277## Making changes {#changes}
278
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000279Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000280CL-specific working branches. Use `repo` to create, upload, and abandon local
281branches. Use `git` to manage changes within a local branch.
282
283```shell
284cd path/to/checkout/frameworks/support/
285repo start my_branch_name .
286# make necessary code changes
287# use git to commit changes
288repo upload --cbr -t .
289```
290
291The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000292`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
293can refer to the
294[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
295for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000296
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000297If you see the following prompt, choose `always`:
298
299```
300Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
301```
302
303If the upload succeeds, you'll see an output like:
304
305```
306remote:
307remote: New Changes:
308remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
309remote:
310```
311
312To edit your change, use `git commit --amend`, and re-upload.
313
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000314NOTE If you encounter issues with `repo upload`, consider running upload with
315trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
316logs can be helpful for reporting issues to the team that manages our git
317servers.
318
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000319NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
320skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
321hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
322to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
323
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700324### Fixing Kotlin code style errors
325
326`repo upload` automatically runs `ktlint`, which will cause the upload to fail
327if your code has style errors, which it reports on the command line like so:
328
329```
330[FAILED] ktlint_hook
331 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
332```
333
334To find and fix these errors, you can run ktlint locally, either in a console
335window or in the Terminal tool in Android Studio. Running in the Terminal tool
336is preferable because it will surface links to your source files/lines so you
337can easily navigate to the code to fix any problems.
338
339First, to run the tool and see all of the errors, run:
340
341`./gradlew module:submodule:ktlint`
342
343where module/submodule are the names used to refer to the module you want to
344check, such as `navigation:navigation-common`. You can also run ktlint on the
345entire project, but that takes longer as it is checking all active modules in
346your project.
347
348Many of the errors that ktlint finds can be automatically fixed by running
349ktlintFormat:
350
351`./gradlew module:submodule:ktlintFormat`
352
353ktlintFormat will report any remaining errors, but you can also run `ktlint`
354again at any time to see an updated list of the remaining errors.
355
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000356## Building {#building}
357
358### Modules and Maven artifacts {#modules-and-maven-artifacts}
359
360To build a specific module, use the module's `assemble` Gradle task. For
361example, if you are working on `core` module use:
362
363```shell
364./gradlew core:core:assemble
365```
366
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000367To make warnings fail your build (same as presubmit), use the `--strict` flag,
368which our gradlew expands into a few correctness-related flags including
369`-Pandroidx.allWarningsAsErrors`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000370
371```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000372./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000373```
374
375To build every module, run the Lint verifier, verify the public API surface, and
376generate the local Maven repository artifact, use the `createArchive` Gradle
377task:
378
379```shell
380./gradlew createArchive
381```
382
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000383To run the complete build task that our build servers use, use the corresponding
384shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000385
386```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000387./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000388```
389
390### Attaching a debugger to the build
391
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700392Gradle tasks, including building a module, may be run or debugged from within
393Android Studio. To start, you need to add the task as a run configuration: you
394can do this manually by adding the corresponding task by clicking on the run
395configuration dropdown, pressing
396[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
397and adding the corresponding task.
398
399You can also run the task through the IDE from the terminal, by using the
400[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
401feature - type in the task you want to run in the in-IDE terminal, and
402`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
403automatically add the configuration to the run configuration menu - you can then
404cancel the task.
405
406Once the task has been added to the run configuration menu, you can start
407debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000408
409Note that debugging will not be available until Gradle sync has completed.
410
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000411#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000412
413Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000414`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000415
AndroidX Core Team6173c652022-05-19 20:43:28 +00004161. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004171. Click the plus in the top left to create a new "Remote" configuration. Give
418 it a name and hit "Ok".
4191. Set breakpoints.
4201. Run your task with added flags: `./gradlew <your_task_here>
421 -Dorg.gradle.debug=true --no-daemon`
4221. Hit the "Debug" button to the right of the configuration dropdown to attach
423 to the process.
424
425#### Troubleshooting the debugger
426
427If you get a "Connection refused" error, it's likely because a gradle daemon is
428still running on the port specified in the config, and you can fix this by
429killing the running gradle daemons:
430
431```shell
432./gradlew --stop
433```
434
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000435NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000436[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
437
438#### Attaching to an annotation processor
439
440Annotation processors run as part of the build, to debug them is similar to
441debugging the build.
442
443For a Java project:
444
445```shell
446./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
447```
448
449For a Kotlin project:
450
451```shell
452./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"
453```
454
455### Optional: Enabling internal menu in IntelliJ/Studio
456
457To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
458Android Lint checks and Metalava, you can enable the
459[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
460which is typically used for plugin and IDE development.
461
462### Reference documentation {#docs}
463
464Our reference docs (Javadocs and KotlinDocs) are published to
465https://developer.android.com/reference/androidx/packages and may be built
466locally.
467
468NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
469run `./gradlew tasks`
470
471#### Javadocs
472
473To build API reference docs for tip-of-tree Java source code, run the Gradle
474task:
475
476```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000477./gradlew doclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000478```
479
AndroidX Core Team8e522ba2021-09-14 07:07:45 -0700480Places the documentation in
481`{androidx-main}/out/androidx/docs-tip-of-tree/build/javadoc`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000482
483#### KotlinDocs
484
485To build API reference docs for tip-of-tree Kotlin source code, run the Gradle
486task:
487
488```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000489./gradlew dokkaKotlinDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000490```
491
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000492Places the documentation in
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000493`{androidx-main}/out/androidx/docs-tip-of-tree/build/dokkaKotlinDocs`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000494
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700495#### Dackka docs
496
497To build API reference docs for both Java and Kotlin source code using Dackka,
498run the Gradle task:
499
500```
501./gradlew dackkaDocs
502```
503
504Location of generated refdocs:
505
506* docs-public (what is published to DAC):
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000507 `{androidx-main}/out/androidx/docs-public/build/dackkaDocs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700508* docs-tip-of-tree:
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000509 `{androidx-main}/out/androidx/docs-tip-of-tree/build/dackkaDocs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700510
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700511The generated docs are plain HTML pages with links that do not work locally.
512These issues are fixed when the docs are published to DAC, but to preview a
513local version of the docs with functioning links and CSS, run:
514
515```
516python3 development/offlinifyDocs/offlinify_dackka_docs.py
517```
518
519You will need to have the `bs4` Python package installed. The CSS used is not
520the same as what will be used when the docs are published.
521
522By default, this command converts the tip-of-tree docs for all libraries. To see
523more options, run:
524
525```
526python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
527```
528
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000529#### Release docs
530
531To build API reference docs for published artifacts formatted for use on
532[d.android.com](http://d.android.com), run the Gradle command:
533
534```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000535./gradlew zipDoclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000536```
537
538This will create the artifact
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000539`{androidx-main}/out/dist/doclava-public-docs-0.zip`. This command builds docs
540based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000541`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
542the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000543`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000544colloquially refer to this two step process of (1) updating `docs-public` and
545(2) checking in a prebuilt artifact into the prebuilts directory as
546[The Prebuilts Dance](releasing_detailed.md#the-prebuilts-dance™). So, to build
547javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000548https://developer.android.com/reference/androidx/packages, both of these steps
549need to be completed.
550
551Once you done the above steps, Kotlin docs will also be generated, with the only
552difference being that we use the Gradle command:
553
554```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000555./gradlew zipDokkaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000556```
557
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000558This will create the artifact `{androidx-main}/out/dist/dokka-public-docs-0.zip`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000559
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700560To generate a zip artifact for both Java and Kotlin source code using Dackka:
561
562```
563./gradlew zipDackkaDocs
564```
565
566This will create the artifact
567`{androidx-main}/out/dist/dackka-public-docs-0.zip`
568
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000569### Updating public APIs {#updating-public-apis}
570
571Public API tasks -- including tracking, linting, and verifying compatibility --
572are run under the following conditions based on the `androidx` configuration
573block, evaluated in order:
574
575* `runApiTasks=Yes` => yes
576* `runApiTasks=No` => no
577* `toolingProject=true` => no
578* `mavenVersion` or group version not set => no
579* Has an existing `api/` directory => yes
580* `publish=SNAPSHOT_AND_RELEASE` => yes
581* Otherwise, no
582
583If you make changes to tracked public APIs, you will need to acknowledge the
584changes by updating the `<component>/api/current.txt` and associated API files.
585This is handled automatically by the `updateApi` Gradle task:
586
587```shell
588# Run updateApi for all modules.
589./gradlew updateApi
590
591# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
592./gradlew :appcompat:appcompat-resources:updateApi
593```
594
595If you change the public APIs without updating the API file, your module will
596still build **but** your CL will fail Treehugger presubmit checks.
597
alanva5fd21b2021-08-20 10:26:46 -0700598#### What are all these files in `api/`? {#updating-public-apis-glossary}
599
600Historical API surfaces are tracked for compatibility and docs generation
601purposes. For each version -- including `current` to represent the tip-of-tree
602version -- we record three different types of API surfaces.
603
604* `<version>.txt`: Public API surface, tracked for compatibility
605* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
606 compatibility where necessary (see
607 [Restricted APIs](api_guidelines.md#restricted-api))
608* `public_plus_experimental_<version>.txt`: Public API surface plus
609 `@RequiresOptIn` experimental API surfaces used for documentation (see
610 [Experimental APIs](api_guidelines.md#experimental-api)) and API review
611
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000612### Release notes & the `Relnote:` tag {#relnote}
613
614Prior to releasing, release notes are pre-populated using a script and placed
615into a Google Doc. The Google Doc is manually double checked by library owners
616before the release goes live. To auto-populate your release notes, you can use
617the semi-optional commit tag `Relnote:` in your commit, which will automatically
618include that message the commit in the pre-populated release notes.
619
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000620The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000621
622#### How to use it?
623
624One-line release note:
625
626``` {.good}
627Relnote: Fixed a critical bug
628```
629
630``` {.good}
631Relnote: "Fixed a critical bug"
632```
633
634``` {.good}
635Relnote: Added the following string function: `myFoo(\"bar\")`
636```
637
638Multi-line release note:
639
640Note: If the following lines do not contain an indent, you may hit b/165570183.
641
642``` {.good}
643Relnote: "We're launching this awesome new feature! It solves a whole list of
644 problems that require a lot of explaining! "
645```
646
647``` {.good}
648Relnote: """Added the following string function: `myFoo("bar")`
649 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
650 """
651```
652
653Opt out of the Relnote tag:
654
655``` {.good}
656Relnote: N/A
657```
658
659``` {.good}
660Relnote: NA
661```
662
663NOT VALID:
664
665``` {.bad}
666Relnote: This is an INVALID multi-line release note. Our current scripts won't
667include anything beyond the first line. The script has no way of knowing when
668the release note actually stops.
669```
670
671``` {.bad}
672Relnote: This is an INVALID multi-line release note. "Quotes" need to be
673 escaped in order for them to be parsed properly.
674```
675
676### Common build errors
677
678#### Diagnosing build failures
679
680If you've encountered a build failure and you're not sure what is triggering it,
681then please run
682`./development/diagnose-build-failure/diagnose-build-failure.sh`.
683
684This script can categorize your build failure into one of the following
685categories:
686
687* The Gradle Daemon is saving state in memory and triggering a failure
688* Your source files have been changed and/or incompatible git commits have
689 been checked out
690* Some file in the out/ dir is triggering an error
691 * If this happens, diagnose-build-failure.sh should also identify which
692 file(s) specifically
693* The build is nondeterministic and/or affected by timestamps
694* The build via gradlew actually passes and this build failure is specific to
695 Android Studio
696
697Some more-specific build failures are listed below in this page.
698
699#### Out-of-date platform prebuilts
700
701Like a normal Android library developed in Android Studio, libraries within
702`androidx` are built against prebuilts of the platform SDK. These are checked in
703to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
704
705If you are developing against pre-release platform APIs in the internal
706`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
707the latest API changes.
708
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000709#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000710
711If Gradle cannot resolve a dependency listed in your `build.gradle`, you may
AndroidX Core Teambae52562022-07-06 13:41:40 -0700712need to import the corresponding artifact into one of the prebuilts
713repositories. These repositories are located under `prebuilts/androidx`. Our
714workflow does not automatically download artifacts from the internet to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000715facilitate reproducible builds even if remote artifacts are changed.
716
AndroidX Core Teambae52562022-07-06 13:41:40 -0700717We use a script to download dependencies, you can learn more about it
718[here](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000719
AndroidX Core Teambae52562022-07-06 13:41:40 -0700720##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000721
722Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700723[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
724Update this file to include a constant for the version of the library that you
725want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000726`build.gradle` dependencies.
727
AndroidX Core Teambae52562022-07-06 13:41:40 -0700728**After** you update the `libs.versions.toml` file with new dependencies, you
729can download them by running:
730
731```shell
732cd frameworks/support &&\
733development/importMaven/importMaven.sh import-toml
734```
735
736This command will resolve everything declared in the `libs.versions.toml` file
737and download missing artifacts into `prebuilts/androidx/external` or
738`prebuilts/androidx/internal`.
739
740Make sure to upload these changes before or concurrently (ex. in the same Gerrit
741topic) with the dependent library code.
742
743##### Downloading a dependency without changing `libs.versions.toml`
744
745You can also download a dependency without changing `libs.versions.toml` file by
746directly invoking:
747
748```shell
749cd frameworks/support &&\
750./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
751```
752
753##### Missing konan dependencies
754
755Kotlin Multiplatform projects need prebuilts to compile native code, which are
756located under `prebuilts/androidx/konan`. **After** you update the kotlin
757version of AndroidX, you should also download necessary prebuilts via:
758
759```shell
760cd frameworks/support &&\
761development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
762```
763
764Please remember to commit changes in the `prebuilts/androidx/konan` repository.
765
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000766#### Dependency verification
767
768If the new dependency you are importing is unsigned, or is signed with a new,
769unrecognized key, then you will need to add new dependency verification metadata
770to indicate to Gradle that this new dependency is trusted. Instructions for how
771to do this are currently in the
772[README](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
773in the development subfolder
774
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000775#### Updating an existing dependency
776
777If an older version of a dependency prebuilt was already checked in, please
778manually remove it within the same CL that adds the new prebuilt. You will also
779need to update `Dependencies.kt` to reflect the version change.
780
781#### My gradle build fails with "Cannot invoke method getURLs() on null object"
782
783You're using Java 9's javac, possibly because you ran envsetup.sh from the
784platform build or specified Java 9 as the global default Java compiler. For the
785former, you can simply open a new shell and avoid running envsetup.sh. For the
786latter, we recommend you set Java 8 as the default compiler using sudo
787update-java-alternatives; however, if you must use Java 9 as the default then
788you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
789
790#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
791
792You probably need to update the prebuilt SDK used by the gradle build. If you
793are referencing new framework APIs, you will need to wait for the framework
794changes to land in an SDK build (or build it yourself) and then land in both
795prebuilts/fullsdk and prebuilts/sdk. See
796[Updating SDK prebuilts](playbook.md#prebuilts-fullsdk) for more information.
797
798#### How do I handle refactoring a framework API referenced from a library?
799
800Because AndroidX must compile against both the current framework and the latest
801SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
802will need to refactor in stages: Remove references to the target APIs from
803AndroidX Perform the refactoring in the framework Update the framework prebuilt
804SDK to incorporate changes in (2) Add references to the refactored APIs in
805AndroidX Update AndroidX prebuilts to incorporate changes in (4)
806
807## Testing {#testing}
808
809AndroidX libraries are expected to include unit or integration test coverage for
810100% of their public API surface. Additionally, all CLs must include a `Test:`
811stanza indicating which tests were used to verify correctness. Any CLs
812implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000813the issue being fixed.
814
815### Running Tests
816
817#### Single Test Class or Method
818
8191. Open the desired test file in Android Studio.
8202. Right-click on a test class or @Test method name and select `Run FooBarTest`
821
822#### Full Test Package
823
8241. In the project side panel open the desired module.
8252. Find the directory with the tests
8263. Right-click on the directory and select `Run androidx.foobar`
827
828### Running Sample Apps
829
830The AndroidX repository has a set of Android applications that exercise AndroidX
831code. These applications can be useful when you want to debug a real running
832application, or reproduce a problem interactively, before writing test code.
833
834These applications are named either `<libraryname>-integration-tests-testapp`,
835or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
836can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000837
838See the [Testing](testing.md) page for more resources on writing, running, and
839monitoring tests.
840
841### AVD Manager
842
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000843The Android Studio instance started by `./studiow` uses a custom SDK directory,
844which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700845Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000846unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000847
848You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700849artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000850directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000851
852```shell
853# Using the default MacOS Android SDK directory...
854ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
855 ../../prebuilts/fullsdk-darwin/system-images
856```
857
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000858## Library snapshots {#snapshots}
859
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000860### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000861
862Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000863snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000864
865```groovy {highlight=context:[buildId]}
866allprojects {
867 repositories {
868 google()
869 jcenter()
870 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
871 }
872}
873```
874
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000875You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
876for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000877
878```groovy {highlight=context:SNAPSHOT}
879dependencies {
880 implementation "androidx.core:core:1.2.0-SNAPSHOT"
881}
882```
883
884### Where to find snapshots
885
886If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
887can find them on either our public-facing build server:
888
889`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
890
891or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
892
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700893`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
894build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000895
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700896`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000897
898### Obtaining a build ID
899
900To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000901[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000902on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
903androidx.dev site.
904
905Note that if you are using androidx.dev, you may substitute `latest` for a build
906ID to use the last known good build.
907
908To manually find the last known good `build-id`, you have several options.
909
910#### Snapshots on androidx.dev
911
912[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
913usable builds.
914
915#### Programmatically via `jq`
916
917Install `jq`:
918
919```shell
920sudo apt-get install jq
921```
922
923```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000924ID=`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 +0000925 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
926```
927
928#### Android build server
929
930Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000931[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000932on ci.android.com.
933
934For `androidx-snapshot` target, wait for the green "last known good build"
935button to load and then click it to follow it to the build artifact URL.
936
937### Using in a Gradle build
938
939To make these artifacts visible to Gradle, you need to add it as a respository:
940
941```groovy
942allprojects {
943 repositories {
944 google()
945 maven {
946 // For all Jetpack libraries (including Compose)
947 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
948 }
949 }
950}
951```
952
953Note that the above requires you to know the `build-id` of the snapshots you
954want.
955
956#### Specifying dependencies
957
958All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
959to use a snapshot artifact, the version in your `build.gradle` will need to be
960updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
961
962For example, to use the `core:core:1.2.0-SHAPSHOT` snapshot, you would add the
963following to your `build.gradle`:
964
965```
966dependencies {
967 ...
968 implementation("androidx.core:core:1.2.0-SNAPSHOT")
969 ...
970}
971```
972
973## FAQ {#faq}
974
975### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
976
977If you're working on a new feature or bug fix in AndroidX, you may want to test
978your changes against another project to verify that the change makes sense in a
979real-world context or that a bug's specific repro case has been fixed.
980
981If you need to be absolutely sure that your test will exactly emulate the
982developer's experience, you can repeatedly build the AndroidX archive and
983rebuild your application. In this case, you will need to create a local build of
984AndroidX's local Maven repository artifact and install it in your Android SDK
985path.
986
987First, use the `createArchive` Gradle task to generate the local Maven
988repository artifact:
989
990```shell
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000991# Creates <path-to-checkout>/out/androidx/build/support_repo/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000992./gradlew createArchive
993```
994
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000995Using for your alternate (non-AndroidX) version of Android Studio open the
996project's 'build.gradle' and add the following within 'repositories' to make
997Android Gradle Plugin look for binaries in newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000998
999```groovy
1000allprojects {
1001 repositories {
1002 ...
1003 maven {
AndroidX Core Team21ccf652022-04-01 14:53:07 +00001004 url "<path-to-sdk>/out/androidx/build/support_repo/"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001005 }
1006 }
1007}
1008```
1009
1010NOTE Gradle resolves dependencies in the order that the repositories are defined
1011(if 2 repositories can resolve the same dependency, the first listed will do so
1012and the second will not). Therefore, if the library you are testing has the same
1013group, artifact, and version as one already published, you will want to list
1014your custom maven repo first.
1015
1016Finally, in the dependencies section of your standalone project's `build.gradle`
1017file, add or update the `implementation` entries to reflect the AndroidX modules
1018that you would like to test. Example:
1019
1020```
1021dependencies {
1022 ...
1023 implementation "androidx.appcompat:appcompat::1.0.0-alpha02"
1024}
1025```
1026
1027If you are testing your changes in the Android Platform code, you can replace
1028the module you are testing
1029`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1030module. We recommend only replacing the module you are modifying instead of the
1031full m2repository to avoid version issues of other modules. You can either take
1032the unzipped directory from
1033`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
1034`<path-to-checkout>/out/androidx/build/support_repo/` after buiding `androidx`.
1035Here is an example of replacing the RecyclerView module:
1036
1037```shell
1038$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1039rm -rf $TARGET;
1040cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1041```
1042
1043Make sure the library versions are the same before and after replacement. Then
1044you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001045
1046### How do I measure library size? {#library-size}
1047
1048Method count and bytecode size are tracked in CI
1049[alongside benchmarks](benchmarking.md#monitoring) to detect regressions.
1050
1051For local measurements, use the `:reportLibraryMetrics` task. For example:
1052
1053```shell
1054./gradlew benchmark:benchmark-macro:reportLibraryMetrics
1055cat ../../out/dist/librarymetrics/androidx.benchmark_benchmark-macro.json
1056```
1057
1058Will output something like: `{"method_count":1256,"bytecode_size":178822}`
1059
1060Note: this only counts the weight of your library's jar/aar, including
1061resources. It does not count library dependencies. It does not account for a
1062minification step (e.g. with R8), as that is dynamic, and done at app build time
1063(and depend on which entrypoints the app uses).
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001064
1065### How do I add content to a library's Overview reference doc page?
1066
1067Put content in a markdown file that ends with `-documentation.md` in the
1068directory that corresponds to the Overview page that you'd like to document.
1069
1070For example, the `androidx.compose.runtime`
1071[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1072includes content from
1073[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).