blob: c536ac36b89a16d541f3dfa87c7223705d7fcf98 [file] [log] [blame] [view]
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001# Getting started
2
3[TOC]
4
5This page describes how to set up your workstation to check out source code,
6make simple changes in Android Studio, and upload commits to Gerrit for review.
7
8This page does **not** cover best practices for the content of changes. Please
Ian Baker186108e2023-11-20 06:54:36 -08009see [Life of a Jetpack Feature](/docs/loaf.md) for details on
AndroidX Core Team76f65452024-01-02 11:39:57 -080010creating and releasing a library or
Ian Baker186108e2023-11-20 06:54:36 -080011[API Guidelines](/docs/api_guidelines/index.md) for best
AndroidX Core Team76f65452024-01-02 11:39:57 -080012practices regarding library development.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000013
14## Workstation setup {#setup}
15
AndroidX Core Teamcc1e9b12022-06-27 13:10:24 -070016This section will help you install the `repo` tool, which is used for Git branch
17and commit management. If you want to learn more about `repo`, see the
18[Repo Command Reference](https://source.android.com/setup/develop/repo).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000019
20### Linux and MacOS {#setup-linux-mac}
21
22First, download `repo` using `curl`.
23
24```shell
25test -d ~/bin || mkdir ~/bin
26curl https://storage.googleapis.com/git-repo-downloads/repo \
27 > ~/bin/repo && chmod 700 ~/bin/repo
28```
29
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080030Then, modify `~/.zshrc` (or `~/.bash_profile` if using `bash`) to ensure you can
AndroidX Core Team21ccf652022-04-01 14:53:07 +000031find local binaries from the command line. We assume you're using `zsh`, but the
AndroidX Core Team685fbcd2022-01-10 14:18:55 -080032following should work with `bash` as well.
AndroidX Core Team2e416b22020-12-03 22:58:07 +000033
34```shell
35export PATH=~/bin:$PATH
36```
37
AndroidX Core Team693e3f82024-05-17 05:25:53 -070038> NOTE: When using quotes (`"~/bin"`), `~` does not expand and the path is
39> invalid. (Possibly `bash` only?)
40
AndroidX Core Team68274512022-04-28 13:10:15 -070041Next, add the following lines to `~/.zshrc` (or `~/.bash_profile` if using
42`bash`) aliasing the `repo` command to run with `python3`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +000043
44```shell
45# Force repo to run with Python3
46function repo() {
AndroidX Core Team21ccf652022-04-01 14:53:07 +000047 command python3 ~/bin/repo $@
AndroidX Core Team2e416b22020-12-03 22:58:07 +000048}
49```
50
AndroidX Core Team68274512022-04-28 13:10:15 -070051Finally, you will need to either start a new terminal session or run `source
52~/.zshrc` (or `source ~/.bash_profile` if using `bash`) to enable the changes.
53
54> NOTE: If you encounter the following warning about Python 2 being no longer
55> supported, you will need to install Python 3 from the
56> [official website](https://www.python.org).
57>
58> ```shell {.bad}
59> repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
60> ```
61
62> NOTE: If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error:
63>
64> ```shell {.bad}
65> Downloading Repo source from https://gerrit.googlesource.com/git-repo
66> fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
67> fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)
68> ```
69>
AndroidX Core Teamf95fde72024-05-07 11:03:03 -070070> Run the `Install Certificates.command` in the Python folder of Application
71> (e.g. `/Applications/Python\ 3.11/Install\ Certificates.command`). For more
72> information about SSL/TLS certificate validation, you can read the "Important
73> Information" displayed during Python installation.
AndroidX Core Team21ccf652022-04-01 14:53:07 +000074
AndroidX Core Team2e416b22020-12-03 22:58:07 +000075### Windows {#setup-win}
76
77Sorry, Windows is not a supported platform for AndroidX development.
78
79## Set up access control {#access}
80
81### Authenticate to AOSP Gerrit {#access-gerrit}
82
83Before you can upload changes, you will need to associate your Google
84credentials with the AOSP Gerrit code review system by signing in to
85[android-review.googlesource.com](https://android-review.googlesource.com) at
86least once using the account you will use to submit patches.
87
88Next, you will need to
89[set up authentication](https://android-review.googlesource.com/new-password).
90This will give you a shell command to update your local Git cookies, which will
91allow you to upload changes.
92
93Finally, you will need to accept the
94[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
95
96## Check out the source {#source}
97
98Like ChromeOS, Chromium, and the Android build system, we develop in the open as
99much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000100[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000101branch of the Android Open Source Project.
102
AndroidX Core Team1c263a02023-03-30 07:12:19 -0700103As of 2023/03/30, you will need about 42 GB for a fully-built checkout.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000104
105### Synchronize the branch {#source-checkout}
106
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000107Use the following commands to check out your branch.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000108
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500109#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000110
111All development should occur in this branch unless otherwise specified by the
112AndroidX Core team.
113
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000114The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000115
116```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000117mkdir androidx-main && cd androidx-main
alanv7ae48942022-09-27 13:53:32 -0700118repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000119 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000120repo sync -c -j8
121```
122
123NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
124you may need to install Python3 and boot strap the SSL certificates in the
125included version of pip. You can execute `Install Certificates.command` under
126`/Applications/Python 3.6/` to do so.
127
AndroidX Core Teamf74ae232022-04-25 11:17:51 -0400128NOTE On MacOS, if you receive a Repo or GPG error like `repo: error: "gpg"
129failed with exit status -6` with cause `md_enable: algorithm 10 not available`
130you may need to install a build of `gpg` that supports SHA512, such as the
131latest version available from [Homebrew](https://brew.sh/) using `brew install
132gpg`.
133
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000134### Increase Git rename limit {#source-config}
135
136To ensure `git` can detect diffs and renames across significant changes (namely,
137the `androidx.*` package rename), we recommend that you set the following `git
138config` properties:
139
140```shell
141git config --global merge.renameLimit 999999
142git config --global diff.renameLimit 999999
143```
144
alanv207674d2022-06-14 11:20:52 -0700145### Set up Git file exclusions {#source-exclude}
146
147Mac users should consider adding `.DS_Store` to a global `.gitignore` file to
148avoid accidentally checking in local metadata files:
149
150```shell
151echo .DS_Store>>~/.gitignore
152git config --global core.excludesFile '~/.gitignore'
153```
154
155### To check out older sources, use the superproject {#source-historical}
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400156
157The
158[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
159contains a history of the matching exact commits of each git repository over
160time, and it can be
161[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
162
alanve9101e42022-01-28 12:05:11 -0800163### Troubleshooting
164
165> NOTE: If the repo manifest changes -- for example when we update the version
166> of `platform-tools` by pointing it to a different git project -- you may see
167> the following error during`repo sync`:
168>
169> ```shell
170> error.GitError: Cannot fetch --force-sync not enabled; cannot overwrite a local work tree.
171> ...
172> error: Unable to fully sync the tree.
173> error: Downloading network changes failed.
174> ```
175>
176> This indicates that Studio or some other process has made changes in the git
177> project that has been replaced or removed. You can force `repo sync` to
178> discard these changes and check out the correct git project by adding the
179> `--force-sync` argument:
180>
181> ```shell
182> repo sync -j32 --force-sync
183> ```
184
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000185## Explore source code from a browser {#code-search}
186
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000187`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000188[code search](https://cs.android.com/androidx/platform/frameworks/support) that
189allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000190URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000191
AndroidX Core Team110f54d2022-10-24 08:35:31 -0700192### Custom search engine for `androidx-main` {#custom-search-engine}
193
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000194We recommend setting up a custom search engine in Chrome as a faster (and
195publicly-accessible) alternative to `cs/`.
196
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001971. Open `chrome://settings/searchEngines`
1981. Click the `Add` button
1991. Enter a name for your search engine, ex. "AndroidX Code Search"
2001. Enter a keyword, ex. "csa"
2011. Enter the following URL:
202 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
2031. Click the `Add` button
204
205Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
206query to search for, e.g. `AppCompatButton file:appcompat`, and press the
207`Enter` key to get to the search result page.
208
209## Develop in Android Studio {#studio}
210
211Library development uses a curated version of Android Studio to ensure
212compatibility between various components of the development workflow.
213
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000214From the `frameworks/support` directory, you can use `./studiow m` (short for
215`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400216correct version of Studio to work on the `main` set of androidx projects
217(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000218[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
219also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400220projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000221
222Next, open the `framework/support` project root from your checkout. If Studio
223asks you which SDK you would like to use, select `Use project SDK`. Importing
224projects may take a while, but once that finishes you can use Studio as you
225normally would for application or library development -- right-click on a test
226or sample to run or debug it, search through classes, and so on.
227
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000228> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
229> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
230> opening `File > Project Structure > Platform Settings > SDKs` and manually
231> setting the Android SDK home path to
232> `<project-root>/prebuilts/fullsdk-<platform>`.
233
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500234### Troubleshooting {#studio-troubleshooting}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000235
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500236* If you've updated to macOS Ventura and receive a "App is damaged and cannot
237 be opened" message when running Studio, *do not* move the app to the Trash.
238 Cancel out of the dialog and open macOS `System Settings > Gatekeeper`, look
239 for `"Android Studio" was blocked`, and click `Open Anyway` to grant an
240 exception. Alternatively, you can navigate to the Studio `.app` file under
241 `frameworks/support/studio` and run it once using `Control+Click` and `Open`
242 to automatically grant an exception.
243* If you've updated to macOS Ventura and receive a "xcrun: error: invalid
244 active developer path" message when running Studio, reinstall Xcode using
245 `xcode-select --install`. If that does not work, you will need to download
246 Xcode.
247* If you get a “Unregistered VCS root detected” message, click “Add root” to
248 enable the Git/VCS integration for Android Studio.
249* If you see any errors (red underlines), click Gradle's elephant button in
250 the toolbar (or `File > Sync Project with Gradle Files`) and they should
251 resolve once the build completes.
252* If you run `./studiow` with a new project set but you're still seeing the
253 old project set in `Project`, use `File > Sync Project with Gradle Files` to
254 force a re-sync.
255* If Android Studio's UI looks scaled up, ex. twice the size it should be, you
256 may need to add the following line to your `studio64.vmoptions` file using
257 `Help > Edit Custom VM Options`: `-Dsun.java2d.uiScale.enabled=false`
258* If you don't see a specific Gradle task listed in Studio's Gradle pane,
259 check the following:
260 * Studio might be running a different project subset than the one
261 intended. For example, `./studiow main` only loads the `main` set of
262 androidx projects; run `./studiow compose` to load the tasks specific to
263 Compose.
264 * Gradle tasks aren't being loaded. Under Studio's settings =>
265 Experimental, make sure that "Do not build Gradle task list during
266 Gradle sync" is unchecked. Note that unchecking this can reduce Studio's
267 performance.
AndroidX Core Team3df24a62022-05-20 06:22:30 -0700268
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000269If in the future you encounter unexpected errors in Studio and you want to check
270for the possibility it is due to some incorrect settings or other generated
271files, you can run `./studiow --clean main <project subset>` or `./studiow
272--reinstall <project subset>` to clean generated files or reinstall Studio.
273
alanv07cfb5e2022-10-12 11:14:08 -0700274### Enabling Compose `@Preview` annotation previews
AndroidX Core Team6173c652022-05-19 20:43:28 +0000275
alanv07cfb5e2022-10-12 11:14:08 -0700276Add the following dependencies to your project's `build.gradle`:
AndroidX Core Team6173c652022-05-19 20:43:28 +0000277
278```groovy
279dependencies {
280 implementation(project(":compose:ui:ui-tooling-preview"))
281 debugImplementation(project(":compose:ui:ui-tooling"))
282}
283```
284
alanv07cfb5e2022-10-12 11:14:08 -0700285Then,
AndroidX Core Team6173c652022-05-19 20:43:28 +0000286[use it like you would on an external project](https://developer.android.com/jetpack/compose/tooling).
287
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000288## Making changes {#changes}
289
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000290Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000291CL-specific working branches. Use `repo` to create, upload, and abandon local
292branches. Use `git` to manage changes within a local branch.
293
294```shell
295cd path/to/checkout/frameworks/support/
296repo start my_branch_name .
297# make necessary code changes
298# use git to commit changes
299repo upload --cbr -t .
300```
301
302The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000303`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
304can refer to the
305[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
306for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000307
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000308If you see the following prompt, choose `always`:
309
310```
311Run hook scripts from https://android.googlesource.com/platform/manifest (yes/always/NO)?
312```
313
314If the upload succeeds, you'll see an output like:
315
316```
317remote:
318remote: New Changes:
319remote: https://android-review.googlesource.com/c/platform/frameworks/support/+/720062 Further README updates
320remote:
321```
322
323To edit your change, use `git commit --amend`, and re-upload.
324
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000325NOTE If you encounter issues with `repo upload`, consider running upload with
326trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
327logs can be helpful for reporting issues to the team that manages our git
328servers.
329
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000330NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
331skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
332hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
333to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
334
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700335### Fixing Kotlin code style errors
336
337`repo upload` automatically runs `ktlint`, which will cause the upload to fail
338if your code has style errors, which it reports on the command line like so:
339
340```
341[FAILED] ktlint_hook
342 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
343```
344
345To find and fix these errors, you can run ktlint locally, either in a console
346window or in the Terminal tool in Android Studio. Running in the Terminal tool
347is preferable because it will surface links to your source files/lines so you
348can easily navigate to the code to fix any problems.
349
350First, to run the tool and see all of the errors, run:
351
352`./gradlew module:submodule:ktlint`
353
354where module/submodule are the names used to refer to the module you want to
355check, such as `navigation:navigation-common`. You can also run ktlint on the
356entire project, but that takes longer as it is checking all active modules in
357your project.
358
359Many of the errors that ktlint finds can be automatically fixed by running
360ktlintFormat:
361
362`./gradlew module:submodule:ktlintFormat`
363
364ktlintFormat will report any remaining errors, but you can also run `ktlint`
365again at any time to see an updated list of the remaining errors.
366
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000367## Building {#building}
368
369### Modules and Maven artifacts {#modules-and-maven-artifacts}
370
371To build a specific module, use the module's `assemble` Gradle task. For
372example, if you are working on `core` module use:
373
374```shell
375./gradlew core:core:assemble
376```
377
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000378To make warnings fail your build (same as presubmit), use the `--strict` flag,
379which our gradlew expands into a few correctness-related flags including
AndroidX Core Team9d812cd2022-09-01 15:42:06 -0700380`-Pandroidx.validateNoUnrecognizedMessages`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000381
382```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000383./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000384```
385
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500386To build every module and generate the local Maven repository artifact, use the
387`createArchive` Gradle task:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000388
389```shell
390./gradlew createArchive
391```
392
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000393To run the complete build task that our build servers use, use the corresponding
394shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000395
396```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000397./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000398```
399
400### Attaching a debugger to the build
401
AndroidX Core Teamd5597b92022-08-09 10:33:00 -0700402Gradle tasks, including building a module, may be run or debugged from within
403Android Studio. To start, you need to add the task as a run configuration: you
404can do this manually by adding the corresponding task by clicking on the run
405configuration dropdown, pressing
406[`Edit Configurations`](https://www.jetbrains.com/help/idea/run-debug-gradle.html),
407and adding the corresponding task.
408
409You can also run the task through the IDE from the terminal, by using the
410[`Run highlighted command using IDE`](https://blog.jetbrains.com/idea/2020/07/run-ide-features-from-the-terminal/)
411feature - type in the task you want to run in the in-IDE terminal, and
412`ctrl+enter` / `cmd+enter` to launch this through the IDE. This will
413automatically add the configuration to the run configuration menu - you can then
414cancel the task.
415
416Once the task has been added to the run configuration menu, you can start
417debugging as with any other task by pressing the `debug` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000418
419Note that debugging will not be available until Gradle sync has completed.
420
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000421#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000422
423Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000424`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000425
AndroidX Core Team6173c652022-05-19 20:43:28 +00004261. From the Run dropdown in Studio, select "Edit Configurations".
AndroidX Core Team2e416b22020-12-03 22:58:07 +00004271. Click the plus in the top left to create a new "Remote" configuration. Give
428 it a name and hit "Ok".
4291. Set breakpoints.
4301. Run your task with added flags: `./gradlew <your_task_here>
431 -Dorg.gradle.debug=true --no-daemon`
4321. Hit the "Debug" button to the right of the configuration dropdown to attach
433 to the process.
434
435#### Troubleshooting the debugger
436
437If you get a "Connection refused" error, it's likely because a gradle daemon is
438still running on the port specified in the config, and you can fix this by
439killing the running gradle daemons:
440
441```shell
442./gradlew --stop
443```
444
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000445NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000446[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
447
448#### Attaching to an annotation processor
449
450Annotation processors run as part of the build, to debug them is similar to
451debugging the build.
452
453For a Java project:
454
455```shell
456./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
457```
458
459For a Kotlin project:
460
461```shell
462./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"
463```
464
465### Optional: Enabling internal menu in IntelliJ/Studio
466
467To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
468Android Lint checks and Metalava, you can enable the
469[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
470which is typically used for plugin and IDE development.
471
472### Reference documentation {#docs}
473
474Our reference docs (Javadocs and KotlinDocs) are published to
475https://developer.android.com/reference/androidx/packages and may be built
476locally.
477
478NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
479run `./gradlew tasks`
480
AndroidX Core Team76f65452024-01-02 11:39:57 -0800481#### Generate docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700482
483To build API reference docs for both Java and Kotlin source code using Dackka,
484run the Gradle task:
485
486```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500487./gradlew docs
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700488```
489
490Location of generated refdocs:
491
492* docs-public (what is published to DAC):
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500493 `{androidx-main}/out/androidx/docs-public/build/docs`
494* docs-tip-of-tree: `{androidx-main}/out/androidx/docs-tip-of-tree/build/docs`
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700495
AndroidX Core Teamd41eada2022-08-12 13:36:49 -0700496The generated docs are plain HTML pages with links that do not work locally.
497These issues are fixed when the docs are published to DAC, but to preview a
498local version of the docs with functioning links and CSS, run:
499
500```
501python3 development/offlinifyDocs/offlinify_dackka_docs.py
502```
503
504You will need to have the `bs4` Python package installed. The CSS used is not
505the same as what will be used when the docs are published.
506
507By default, this command converts the tip-of-tree docs for all libraries. To see
508more options, run:
509
510```
511python3 development/offlinifyDocs/offlinify_dackka_docs.py --help
512```
513
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000514#### Release docs
515
516To build API reference docs for published artifacts formatted for use on
517[d.android.com](http://d.android.com), run the Gradle command:
518
519```
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500520./gradlew zipDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000521```
522
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500523This will create the artifact `{androidx-main}/out/dist/docs-public-0.zip`. This
524command builds docs based on the version specified in
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000525`{androidx-main-checkout}/frameworks/support/docs-public/build.gradle` and uses
526the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000527`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Team4e1909a2021-10-20 15:04:04 +0000528colloquially refer to this two step process of (1) updating `docs-public` and
529(2) checking in a prebuilt artifact into the prebuilts directory as
Ian Baker186108e2023-11-20 06:54:36 -0800530[The Prebuilts Dance](/docs/releasing_prebuilts_dance.md#the-prebuilts-dance™).
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500531So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000532https://developer.android.com/reference/androidx/packages, both of these steps
533need to be completed.
534
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000535### Updating public APIs {#updating-public-apis}
536
537Public API tasks -- including tracking, linting, and verifying compatibility --
538are run under the following conditions based on the `androidx` configuration
539block, evaluated in order:
540
541* `runApiTasks=Yes` => yes
542* `runApiTasks=No` => no
543* `toolingProject=true` => no
544* `mavenVersion` or group version not set => no
545* Has an existing `api/` directory => yes
546* `publish=SNAPSHOT_AND_RELEASE` => yes
547* Otherwise, no
548
549If you make changes to tracked public APIs, you will need to acknowledge the
550changes by updating the `<component>/api/current.txt` and associated API files.
551This is handled automatically by the `updateApi` Gradle task:
552
553```shell
554# Run updateApi for all modules.
555./gradlew updateApi
556
557# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
558./gradlew :appcompat:appcompat-resources:updateApi
559```
560
561If you change the public APIs without updating the API file, your module will
562still build **but** your CL will fail Treehugger presubmit checks.
563
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500564NOTE The `updateApi` task does not generate versioned API files (e.g.
565`1.0.0-beta01.txt`) during a library's `alpha`, `rc` or stable cycles. The task
566will always generate `current.txt` API files.
567
alanva5fd21b2021-08-20 10:26:46 -0700568#### What are all these files in `api/`? {#updating-public-apis-glossary}
569
570Historical API surfaces are tracked for compatibility and docs generation
571purposes. For each version -- including `current` to represent the tip-of-tree
572version -- we record three different types of API surfaces.
573
574* `<version>.txt`: Public API surface, tracked for compatibility
575* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
576 compatibility where necessary (see
Ian Baker186108e2023-11-20 06:54:36 -0800577 [Restricted APIs](/docs/api_guidelines/index.md#restricted-api))
alanva5fd21b2021-08-20 10:26:46 -0700578* `public_plus_experimental_<version>.txt`: Public API surface plus
579 `@RequiresOptIn` experimental API surfaces used for documentation (see
Ian Baker186108e2023-11-20 06:54:36 -0800580 [Experimental APIs](/docs/api_guidelines/index.md#experimental-api))
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500581 and API review
alanva5fd21b2021-08-20 10:26:46 -0700582
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000583### Release notes & the `Relnote:` tag {#relnote}
584
585Prior to releasing, release notes are pre-populated using a script and placed
586into a Google Doc. The Google Doc is manually double checked by library owners
587before the release goes live. To auto-populate your release notes, you can use
588the semi-optional commit tag `Relnote:` in your commit, which will automatically
589include that message the commit in the pre-populated release notes.
590
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000591The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000592
593#### How to use it?
594
595One-line release note:
596
597``` {.good}
598Relnote: Fixed a critical bug
599```
600
601``` {.good}
602Relnote: "Fixed a critical bug"
603```
604
605``` {.good}
606Relnote: Added the following string function: `myFoo(\"bar\")`
607```
608
609Multi-line release note:
610
611Note: If the following lines do not contain an indent, you may hit b/165570183.
612
613``` {.good}
614Relnote: "We're launching this awesome new feature! It solves a whole list of
615 problems that require a lot of explaining! "
616```
617
618``` {.good}
619Relnote: """Added the following string function: `myFoo("bar")`
620 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
621 """
622```
623
624Opt out of the Relnote tag:
625
626``` {.good}
627Relnote: N/A
628```
629
630``` {.good}
631Relnote: NA
632```
633
634NOT VALID:
635
636``` {.bad}
637Relnote: This is an INVALID multi-line release note. Our current scripts won't
638include anything beyond the first line. The script has no way of knowing when
639the release note actually stops.
640```
641
642``` {.bad}
643Relnote: This is an INVALID multi-line release note. "Quotes" need to be
644 escaped in order for them to be parsed properly.
645```
646
647### Common build errors
648
649#### Diagnosing build failures
650
651If you've encountered a build failure and you're not sure what is triggering it,
652then please run
653`./development/diagnose-build-failure/diagnose-build-failure.sh`.
654
655This script can categorize your build failure into one of the following
656categories:
657
658* The Gradle Daemon is saving state in memory and triggering a failure
659* Your source files have been changed and/or incompatible git commits have
660 been checked out
661* Some file in the out/ dir is triggering an error
662 * If this happens, diagnose-build-failure.sh should also identify which
663 file(s) specifically
664* The build is nondeterministic and/or affected by timestamps
665* The build via gradlew actually passes and this build failure is specific to
666 Android Studio
667
668Some more-specific build failures are listed below in this page.
669
670#### Out-of-date platform prebuilts
671
672Like a normal Android library developed in Android Studio, libraries within
673`androidx` are built against prebuilts of the platform SDK. These are checked in
674to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
675
676If you are developing against pre-release platform APIs in the internal
677`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
678the latest API changes.
679
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000680#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000681
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800682If Gradle cannot resolve a dependency listed in your `build.gradle`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000683
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800684* You will probably want to import the missing artifact via
685 [importMaven.sh](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/importMaven/README.md)
686
687 * We store artifacts in the prebuilts repositories under
688 `prebuilts/androidx` to facilitate reproducible builds even if remote
689 artifacts are changed.
690
691* You may need to [establish trust for](#dependency-verification) the new
692 artifact
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000693
AndroidX Core Teambae52562022-07-06 13:41:40 -0700694##### Importing dependencies in `libs.versions.toml`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000695
696Libraries typically reference dependencies using constants defined in
AndroidX Core Teambae52562022-07-06 13:41:40 -0700697[`libs.versions.toml`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:gradle/libs.versions.toml).
698Update this file to include a constant for the version of the library that you
699want to depend on. You will reference this constant in your library's
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000700`build.gradle` dependencies.
701
AndroidX Core Teambae52562022-07-06 13:41:40 -0700702**After** you update the `libs.versions.toml` file with new dependencies, you
703can download them by running:
704
705```shell
706cd frameworks/support &&\
707development/importMaven/importMaven.sh import-toml
708```
709
710This command will resolve everything declared in the `libs.versions.toml` file
711and download missing artifacts into `prebuilts/androidx/external` or
712`prebuilts/androidx/internal`.
713
714Make sure to upload these changes before or concurrently (ex. in the same Gerrit
715topic) with the dependent library code.
716
717##### Downloading a dependency without changing `libs.versions.toml`
718
719You can also download a dependency without changing `libs.versions.toml` file by
720directly invoking:
721
722```shell
723cd frameworks/support &&\
724./development/importMaven/importMaven.sh someGroupId:someArtifactId:someVersion
725```
726
727##### Missing konan dependencies
728
729Kotlin Multiplatform projects need prebuilts to compile native code, which are
730located under `prebuilts/androidx/konan`. **After** you update the kotlin
731version of AndroidX, you should also download necessary prebuilts via:
732
733```shell
734cd frameworks/support &&\
735development/importMaven/importMaven.sh import-konan-binaries --konan-compiler-version <new-kotlin-version>
736```
737
738Please remember to commit changes in the `prebuilts/androidx/konan` repository.
739
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000740#### Dependency verification
741
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800742If you import a new dependency that is either unsigned or is signed with a new,
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000743unrecognized key, then you will need to add new dependency verification metadata
AndroidX Core Team8dcb0d12023-03-02 11:18:52 -0800744to indicate to Gradle that this new dependency is trusted. See the instructions
745[here](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/gradle/README.md)
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000746
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000747#### Updating an existing dependency
748
749If an older version of a dependency prebuilt was already checked in, please
750manually remove it within the same CL that adds the new prebuilt. You will also
751need to update `Dependencies.kt` to reflect the version change.
752
753#### My gradle build fails with "Cannot invoke method getURLs() on null object"
754
755You're using Java 9's javac, possibly because you ran envsetup.sh from the
756platform build or specified Java 9 as the global default Java compiler. For the
757former, you can simply open a new shell and avoid running envsetup.sh. For the
758latter, we recommend you set Java 8 as the default compiler using sudo
759update-java-alternatives; however, if you must use Java 9 as the default then
760you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
761
762#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
763
764You probably need to update the prebuilt SDK used by the gradle build. If you
765are referencing new framework APIs, you will need to wait for the framework
766changes to land in an SDK build (or build it yourself) and then land in both
767prebuilts/fullsdk and prebuilts/sdk. See
Ian Baker186108e2023-11-20 06:54:36 -0800768[Updating SDK prebuilts](/docs/playbook.md#prebuilts-fullsdk)
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500769for more information.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000770
771#### How do I handle refactoring a framework API referenced from a library?
772
773Because AndroidX must compile against both the current framework and the latest
774SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
AndroidX Core Team5ad2f7f2023-01-20 12:26:18 -0500775will need to refactor in stages:
776
7771. Remove references to the target APIs from AndroidX
7782. Perform the refactoring in the framework
7793. Update the framework prebuilt SDK to incorporate changes in (2)
7804. Add references to the refactored APIs in AndroidX
7815. Update AndroidX prebuilts to incorporate changes in (4)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000782
783## Testing {#testing}
784
785AndroidX libraries are expected to include unit or integration test coverage for
786100% of their public API surface. Additionally, all CLs must include a `Test:`
787stanza indicating which tests were used to verify correctness. Any CLs
788implementing bug fixes are expected to include new regression tests specific to
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000789the issue being fixed.
790
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700791### Running tests {#run-tests}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000792
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700793Generally, tests in the AndroidX repository should be run through the Android
794Studio UI. You can also run tests from the command line or via remote devices on
795FTL, see
Ian Baker186108e2023-11-20 06:54:36 -0800796[Running unit and integration tests](/docs/testing.md#running)
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700797for details.
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000798
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700799#### Single test class or method
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000800
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008011. Open the desired test file in Android Studio
8022. Right-click on a test class or `@Test` method name and select `Run <name>`
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000803
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -0700804#### Full test package
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000805
AndroidX Core Teambf2f7f32023-04-24 12:58:05 -07008061. In the `Project` side panel, open the desired module
8072. Find the package directory with the tests
8083. Right-click on the directory and select `Run <package>`
809
810### Running sample apps {#run-samples}
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000811
812The AndroidX repository has a set of Android applications that exercise AndroidX
813code. These applications can be useful when you want to debug a real running
814application, or reproduce a problem interactively, before writing test code.
815
816These applications are named either `<libraryname>-integration-tests-testapp`,
817or `support-\*-demos` (e.g. `support-v4-demos` or `support-leanback-demos`). You
818can run them by clicking `Run > Run ...` and choosing the desired application.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000819
Ian Baker186108e2023-11-20 06:54:36 -0800820See the [Testing](/docs/testing.md) page for more resources on
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500821writing, running, and monitoring tests.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000822
823### AVD Manager
824
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000825The Android Studio instance started by `./studiow` uses a custom SDK directory,
826which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700827Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000828unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000829
830You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700831artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000832directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000833
834```shell
835# Using the default MacOS Android SDK directory...
836ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
837 ../../prebuilts/fullsdk-darwin/system-images
838```
839
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000840## Library snapshots {#snapshots}
841
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000842### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000843
844Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000845snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000846
847```groovy {highlight=context:[buildId]}
848allprojects {
849 repositories {
850 google()
851 jcenter()
852 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
853 }
854}
855```
856
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000857You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
858for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000859
860```groovy {highlight=context:SNAPSHOT}
861dependencies {
862 implementation "androidx.core:core:1.2.0-SNAPSHOT"
863}
864```
865
866### Where to find snapshots
867
868If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
869can find them on either our public-facing build server:
870
871`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
872
873or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
874
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700875`https://androidx.dev/snapshots/builds/<build-id>/artifacts` for a specific
876build ID
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000877
AndroidX Core Team6e4288b2022-07-13 13:53:43 -0700878`https://androidx.dev/snapshots/latest/artifacts` for tip-of-tree snapshots
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000879
880### Obtaining a build ID
881
882To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000883[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000884on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
885androidx.dev site.
886
887Note that if you are using androidx.dev, you may substitute `latest` for a build
888ID to use the last known good build.
889
890To manually find the last known good `build-id`, you have several options.
891
892#### Snapshots on androidx.dev
893
894[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
895usable builds.
896
897#### Programmatically via `jq`
898
899Install `jq`:
900
901```shell
902sudo apt-get install jq
903```
904
905```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000906ID=`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 +0000907 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
908```
909
910#### Android build server
911
912Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000913[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000914on ci.android.com.
915
916For `androidx-snapshot` target, wait for the green "last known good build"
917button to load and then click it to follow it to the build artifact URL.
918
919### Using in a Gradle build
920
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500921To make these artifacts visible to Gradle, you need to add it as a repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000922
923```groovy
924allprojects {
925 repositories {
926 google()
927 maven {
928 // For all Jetpack libraries (including Compose)
929 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
930 }
931 }
932}
933```
934
935Note that the above requires you to know the `build-id` of the snapshots you
936want.
937
938#### Specifying dependencies
939
940All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
941to use a snapshot artifact, the version in your `build.gradle` will need to be
942updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
943
AndroidX Core Team5fa61982023-01-13 10:43:41 -0500944For example, to use the `core:core:1.2.0-SNAPSHOT` snapshot, you would add the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000945following to your `build.gradle`:
946
947```
948dependencies {
949 ...
950 implementation("androidx.core:core:1.2.0-SNAPSHOT")
951 ...
952}
953```
954
955## FAQ {#faq}
956
957### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
958
959If you're working on a new feature or bug fix in AndroidX, you may want to test
960your changes against another project to verify that the change makes sense in a
961real-world context or that a bug's specific repro case has been fixed.
962
963If you need to be absolutely sure that your test will exactly emulate the
964developer's experience, you can repeatedly build the AndroidX archive and
965rebuild your application. In this case, you will need to create a local build of
966AndroidX's local Maven repository artifact and install it in your Android SDK
967path.
968
969First, use the `createArchive` Gradle task to generate the local Maven
970repository artifact:
971
972```shell
AndroidX Core Team21ccf652022-04-01 14:53:07 +0000973# Creates <path-to-checkout>/out/androidx/build/support_repo/
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000974./gradlew createArchive
975```
976
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700977Using your alternate (non-AndroidX) version of Android Studio open the project's
978`settings.gradle.kts` and add the following within
979`dependencyResolutionManagement` to make your project look for binaries in the
980newly built repository:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000981
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700982```kotlin
983dependencyResolutionManagement {
984 repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000985 repositories {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700986 google()
987 mavenCentral()
988 // Add this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000989 maven {
AndroidX Core Teamd7195922023-10-02 08:43:33 -0700990 setUrl("<path-to-sdk>/out/androidx/build/support_repo/")
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000991 }
992 }
993}
994```
995
996NOTE Gradle resolves dependencies in the order that the repositories are defined
997(if 2 repositories can resolve the same dependency, the first listed will do so
998and the second will not). Therefore, if the library you are testing has the same
999group, artifact, and version as one already published, you will want to list
1000your custom maven repo first.
1001
1002Finally, in the dependencies section of your standalone project's `build.gradle`
1003file, add or update the `implementation` entries to reflect the AndroidX modules
1004that you would like to test. Example:
1005
1006```
1007dependencies {
1008 ...
AndroidX Core Teamd7195922023-10-02 08:43:33 -07001009 implementation "androidx.appcompat:appcompat:1.0.0-alpha02"
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001010}
1011```
1012
1013If you are testing your changes in the Android Platform code, you can replace
1014the module you are testing
1015`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
1016module. We recommend only replacing the module you are modifying instead of the
1017full m2repository to avoid version issues of other modules. You can either take
1018the unzipped directory from
1019`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001020`<path-to-checkout>/out/androidx/build/support_repo/` after building `androidx`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +00001021Here is an example of replacing the RecyclerView module:
1022
1023```shell
1024$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
1025rm -rf $TARGET;
1026cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
1027```
1028
1029Make sure the library versions are the same before and after replacement. Then
1030you can build the Android platform code with the new `androidx` code.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001031
1032### How do I measure library size? {#library-size}
1033
1034Method count and bytecode size are tracked in CI
Ian Baker186108e2023-11-20 06:54:36 -08001035[alongside benchmarks](/docs/benchmarking.md#monitoring) to
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001036detect regressions.
AndroidX Core Team4cc85fa2021-11-23 15:58:34 +00001037
1038For local measurements, use the `:reportLibraryMetrics` task. For example:
1039
1040```shell
1041./gradlew benchmark:benchmark-macro:reportLibraryMetrics
1042cat ../../out/dist/librarymetrics/androidx.benchmark_benchmark-macro.json
1043```
1044
1045Will output something like: `{"method_count":1256,"bytecode_size":178822}`
1046
1047Note: this only counts the weight of your library's jar/aar, including
1048resources. It does not count library dependencies. It does not account for a
1049minification step (e.g. with R8), as that is dynamic, and done at app build time
1050(and depend on which entrypoints the app uses).
AndroidX Core Teamf74ae232022-04-25 11:17:51 -04001051
1052### How do I add content to a library's Overview reference doc page?
1053
1054Put content in a markdown file that ends with `-documentation.md` in the
1055directory that corresponds to the Overview page that you'd like to document.
1056
1057For example, the `androidx.compose.runtime`
1058[Overview page](https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary)
1059includes content from
1060[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 -05001061
1062### How do I enable MultiDex for my library?
1063
1064Go to your project/app level build.gradle file, and add
1065
1066```
1067android {
1068 defaultConfig {
1069 multiDexEnabled = true
1070 }
1071}
1072```
1073
1074as well as `androidTestImplementation(libs.multidex)` to the dependenices block.
1075
AndroidX Core Team76f65452024-01-02 11:39:57 -08001076If you want it enabled for the application and not test APK, add
AndroidX Core Team5fa61982023-01-13 10:43:41 -05001077`implementation(libs.multidex)` to the dependencies block instead. Any prior
1078failures may not re-occur now that the software is multi-dexed. Rerun the build.