blob: e1c95376d733ab9f56aa1f91cbd201e7193a3694 [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 Team0db91f02021-05-06 22:45:18 +000015You will need to install the
16[`repo`](https://source.android.com/setup/develop#repo) tool, which is used for
17Git branch and commit management. If you want to learn more about `repo`, see
18the [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
30Then, modify `~/.bash_profile` (if using `bash`) to ensure you can find local
31binaries from the command line.
32
33```shell
34export PATH=~/bin:$PATH
35```
36
37You will need to either start a new terminal session or run `source
38~/.bash_profile` to pick up the new path.
39
40If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error or warning about
41Python 2 being no longer supported, you will need to install Python 3 and alias
42your `repo` command to run with `python3`.
43
44```shell {.bad}
45repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
46```
47
48```shell {.bad}
49Downloading Repo source from https://gerrit.googlesource.com/git-repo
50fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
51fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
52```
53
54First, install Python 3 from the [official website](https://www.python.org).
55Please read the "Important Information" displayed during installation for
56information about SSL/TLS certificate validation and the running the "Install
57Certificates.command".
58
59Next, open your `~/.bash_profile` and add the following lines to wrap the `repo`
60command:
61
62```shell
63# Force repo to run with Python3
64function repo() {
65 command python3 "$(which repo)" $@
66}
67```
68
69### Windows {#setup-win}
70
71Sorry, Windows is not a supported platform for AndroidX development.
72
73## Set up access control {#access}
74
75### Authenticate to AOSP Gerrit {#access-gerrit}
76
77Before you can upload changes, you will need to associate your Google
78credentials with the AOSP Gerrit code review system by signing in to
79[android-review.googlesource.com](https://android-review.googlesource.com) at
80least once using the account you will use to submit patches.
81
82Next, you will need to
83[set up authentication](https://android-review.googlesource.com/new-password).
84This will give you a shell command to update your local Git cookies, which will
85allow you to upload changes.
86
87Finally, you will need to accept the
88[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
89
90## Check out the source {#source}
91
92Like ChromeOS, Chromium, and the Android build system, we develop in the open as
93much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +000094[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +000095branch of the Android Open Source Project.
96
97As of 2020/03/20, you will need about 38 GB for a fully-built checkout.
98
99### Synchronize the branch {#source-checkout}
100
101Use the following `repo` commands to check out your branch.
102
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500103#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000104
105All development should occur in this branch unless otherwise specified by the
106AndroidX Core team.
107
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000108The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000109
110```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000111mkdir androidx-main && cd androidx-main
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000112repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000113 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000114repo sync -c -j8
115```
116
117NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
118you may need to install Python3 and boot strap the SSL certificates in the
119included version of pip. You can execute `Install Certificates.command` under
120`/Applications/Python 3.6/` to do so.
121
122### Increase Git rename limit {#source-config}
123
124To ensure `git` can detect diffs and renames across significant changes (namely,
125the `androidx.*` package rename), we recommend that you set the following `git
126config` properties:
127
128```shell
129git config --global merge.renameLimit 999999
130git config --global diff.renameLimit 999999
131```
132
AndroidX Core Teamc2e3ad52021-08-17 13:40:01 -0400133### To check out older source, use the superproject
134
135The
136[git superproject](https://android.googlesource.com/platform/superproject/+/androidx-main)
137contains a history of the matching exact commits of each git repository over
138time, and it can be
139[checked out directly via git](https://stackoverflow.com/questions/3796927/how-to-git-clone-including-submodules)
140
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000141## Explore source code from a browser {#code-search}
142
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000143`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000144[code search](https://cs.android.com/androidx/platform/frameworks/support) that
145allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000146URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000147
148We recommend setting up a custom search engine in Chrome as a faster (and
149publicly-accessible) alternative to `cs/`.
150
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000151### Custom search engine for `androidx-main` {#custom-search-engine}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000152
1531. Open `chrome://settings/searchEngines`
1541. Click the `Add` button
1551. Enter a name for your search engine, ex. "AndroidX Code Search"
1561. Enter a keyword, ex. "csa"
1571. Enter the following URL:
158 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
1591. Click the `Add` button
160
161Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
162query to search for, e.g. `AppCompatButton file:appcompat`, and press the
163`Enter` key to get to the search result page.
164
165## Develop in Android Studio {#studio}
166
167Library development uses a curated version of Android Studio to ensure
168compatibility between various components of the development workflow.
169
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000170From the `frameworks/support` directory, you can use `./studiow m` (short for
171`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400172correct version of Studio to work on the `main` set of androidx projects
173(non-Compose Jetpack libraries).
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000174[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
175also supports several other arguments like `all` for other subsets of the
AndroidX Core Team23c50442021-05-18 13:03:40 -0400176projects (run `./studiow` for help).
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000177
178Next, open the `framework/support` project root from your checkout. If Studio
179asks you which SDK you would like to use, select `Use project SDK`. Importing
180projects may take a while, but once that finishes you can use Studio as you
181normally would for application or library development -- right-click on a test
182or sample to run or debug it, search through classes, and so on.
183
184If you see any errors (red underlines), click Gradle's elephant button in the
185toolbar ("Sync Project with Gradle Files") and they should resolve once the
186build completes.
187
188> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
189> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
190> opening `File > Project Structure > Platform Settings > SDKs` and manually
191> setting the Android SDK home path to
192> `<project-root>/prebuilts/fullsdk-<platform>`.
193
194> NOTE: If Android Studio's UI looks scaled up, ex. twice the size it should be,
195> you may need to add the following line to your `studio64.vmoptions` file using
196> `Help -> Edit Custom VM Options`:
197>
198> ```
199> -Dsun.java2d.uiScale.enabled=false
200> ```
201
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000202If in the future you encounter unexpected errors in Studio and you want to check
203for the possibility it is due to some incorrect settings or other generated
204files, you can run `./studiow --clean main <project subset>` or `./studiow
205--reinstall <project subset>` to clean generated files or reinstall Studio.
206
AndroidX Core Teame80aab72021-09-29 08:44:33 -0700207> Tip: If you don't see a specific Gradle task listed in Studio's Gradle pane,
208> check the following:
209>
210> * Studio might be running a different project subset than the one intended.
211> For example, `./studiow main` only loads the `main` set of androidx
212> projects; run `./studiow compose` to load the tasks specific to Compose.
213>
214> * Gradle tasks aren't being loaded. Under Studio's settings => Experimental,
215> make sure that "Do not build Gradle task list during Gradle sync" is
216> unchecked. (Note that unchecking this can reduce Studio's performance)
217
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000218## Making changes {#changes}
219
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000220Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000221CL-specific working branches. Use `repo` to create, upload, and abandon local
222branches. Use `git` to manage changes within a local branch.
223
224```shell
225cd path/to/checkout/frameworks/support/
226repo start my_branch_name .
227# make necessary code changes
228# use git to commit changes
229repo upload --cbr -t .
230```
231
232The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000233`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
234can refer to the
235[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
236for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000237
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000238NOTE If you encounter issues with `repo upload`, consider running upload with
239trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
240logs can be helpful for reporting issues to the team that manages our git
241servers.
242
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000243NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
244skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
245hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
246to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
247
AndroidX Core Teamdeda2cf2021-08-06 15:14:40 -0700248### Fixing Kotlin code style errors
249
250`repo upload` automatically runs `ktlint`, which will cause the upload to fail
251if your code has style errors, which it reports on the command line like so:
252
253```
254[FAILED] ktlint_hook
255 [path]/MessageListAdapter.kt:36:69: Missing newline before ")"
256```
257
258To find and fix these errors, you can run ktlint locally, either in a console
259window or in the Terminal tool in Android Studio. Running in the Terminal tool
260is preferable because it will surface links to your source files/lines so you
261can easily navigate to the code to fix any problems.
262
263First, to run the tool and see all of the errors, run:
264
265`./gradlew module:submodule:ktlint`
266
267where module/submodule are the names used to refer to the module you want to
268check, such as `navigation:navigation-common`. You can also run ktlint on the
269entire project, but that takes longer as it is checking all active modules in
270your project.
271
272Many of the errors that ktlint finds can be automatically fixed by running
273ktlintFormat:
274
275`./gradlew module:submodule:ktlintFormat`
276
277ktlintFormat will report any remaining errors, but you can also run `ktlint`
278again at any time to see an updated list of the remaining errors.
279
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000280## Building {#building}
281
282### Modules and Maven artifacts {#modules-and-maven-artifacts}
283
284To build a specific module, use the module's `assemble` Gradle task. For
285example, if you are working on `core` module use:
286
287```shell
288./gradlew core:core:assemble
289```
290
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000291To make warnings fail your build (same as presubmit), use the `--strict` flag,
292which our gradlew expands into a few correctness-related flags including
293`-Pandroidx.allWarningsAsErrors`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000294
295```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000296./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000297```
298
299To build every module, run the Lint verifier, verify the public API surface, and
300generate the local Maven repository artifact, use the `createArchive` Gradle
301task:
302
303```shell
304./gradlew createArchive
305```
306
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000307To run the complete build task that our build servers use, use the corresponding
308shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000309
310```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000311./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000312```
313
314### Attaching a debugger to the build
315
316Gradle tasks, including building a module, may be run or debugged from Android
317Studio's `Gradle` pane by finding the task to be debugged -- for example,
318`androidx > androidx > appcompat > appcompat > build > assemble` --
319right-clicking on it, and then selecting `Debug...`.
320
321Note that debugging will not be available until Gradle sync has completed.
322
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000323#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000324
325Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000326`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000327
3281. From the configurations dropdown in Studio, select "Edit Configurations".
3291. Click the plus in the top left to create a new "Remote" configuration. Give
330 it a name and hit "Ok".
3311. Set breakpoints.
3321. Run your task with added flags: `./gradlew <your_task_here>
333 -Dorg.gradle.debug=true --no-daemon`
3341. Hit the "Debug" button to the right of the configuration dropdown to attach
335 to the process.
336
337#### Troubleshooting the debugger
338
339If you get a "Connection refused" error, it's likely because a gradle daemon is
340still running on the port specified in the config, and you can fix this by
341killing the running gradle daemons:
342
343```shell
344./gradlew --stop
345```
346
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000347NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000348[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
349
350#### Attaching to an annotation processor
351
352Annotation processors run as part of the build, to debug them is similar to
353debugging the build.
354
355For a Java project:
356
357```shell
358./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
359```
360
361For a Kotlin project:
362
363```shell
364./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"
365```
366
367### Optional: Enabling internal menu in IntelliJ/Studio
368
369To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
370Android Lint checks and Metalava, you can enable the
371[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
372which is typically used for plugin and IDE development.
373
374### Reference documentation {#docs}
375
376Our reference docs (Javadocs and KotlinDocs) are published to
377https://developer.android.com/reference/androidx/packages and may be built
378locally.
379
380NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
381run `./gradlew tasks`
382
383#### Javadocs
384
385To build API reference docs for tip-of-tree Java source code, run the Gradle
386task:
387
388```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000389./gradlew doclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000390```
391
AndroidX Core Team8e522ba2021-09-14 07:07:45 -0700392Places the documentation in
393`{androidx-main}/out/androidx/docs-tip-of-tree/build/javadoc`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000394
395#### KotlinDocs
396
397To build API reference docs for tip-of-tree Kotlin source code, run the Gradle
398task:
399
400```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000401./gradlew dokkaKotlinDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000402```
403
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000404Places the documentation in
405`{androidx-main}/out/dist/out/androidx/docs-tip-of-tree/build/dokkaKotlinDocs`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000406
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700407#### Dackka docs
408
409To build API reference docs for both Java and Kotlin source code using Dackka,
410run the Gradle task:
411
412```
413./gradlew dackkaDocs
414```
415
416Location of generated refdocs:
417
418* docs-public (what is published to DAC):
419 `{androidx-main}/out/dist/out/androidx/docs-public/build/dackkaDocs`
420* docs-tip-of-tree:
421 `{androidx-main}/out/dist/out/androidx/docs-tip-of-tree/build/dackkaDocs`
422
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000423#### Release docs
424
425To build API reference docs for published artifacts formatted for use on
426[d.android.com](http://d.android.com), run the Gradle command:
427
428```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000429./gradlew zipDoclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000430```
431
432This will create the artifact
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000433`{androidx-main}/out/dist/doclava-public-docs-0.zip`. This command builds docs
434based on the version specified in
435`{androidx-main-checkout}/frameworks/support/buildSrc/src/main/kotlin/androidx/build/PublishDocsRules.kt`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000436and uses the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000437`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000438colloquially refer to this two step process of (1) updating
439`PublishDocsRules.kt` and (2) checking in a prebuilt artifact into the prebuilts
440directory as [The Prebuilts Dance](releasing_detailed.md#the-prebuilts-danceâ„¢).
441So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000442https://developer.android.com/reference/androidx/packages, both of these steps
443need to be completed.
444
445Once you done the above steps, Kotlin docs will also be generated, with the only
446difference being that we use the Gradle command:
447
448```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000449./gradlew zipDokkaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000450```
451
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000452This will create the artifact `{androidx-main}/out/dist/dokka-public-docs-0.zip`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000453
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700454To generate a zip artifact for both Java and Kotlin source code using Dackka:
455
456```
457./gradlew zipDackkaDocs
458```
459
460This will create the artifact
461`{androidx-main}/out/dist/dackka-public-docs-0.zip`
462
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000463### Updating public APIs {#updating-public-apis}
464
465Public API tasks -- including tracking, linting, and verifying compatibility --
466are run under the following conditions based on the `androidx` configuration
467block, evaluated in order:
468
469* `runApiTasks=Yes` => yes
470* `runApiTasks=No` => no
471* `toolingProject=true` => no
472* `mavenVersion` or group version not set => no
473* Has an existing `api/` directory => yes
474* `publish=SNAPSHOT_AND_RELEASE` => yes
475* Otherwise, no
476
477If you make changes to tracked public APIs, you will need to acknowledge the
478changes by updating the `<component>/api/current.txt` and associated API files.
479This is handled automatically by the `updateApi` Gradle task:
480
481```shell
482# Run updateApi for all modules.
483./gradlew updateApi
484
485# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
486./gradlew :appcompat:appcompat-resources:updateApi
487```
488
489If you change the public APIs without updating the API file, your module will
490still build **but** your CL will fail Treehugger presubmit checks.
491
alanva5fd21b2021-08-20 10:26:46 -0700492#### What are all these files in `api/`? {#updating-public-apis-glossary}
493
494Historical API surfaces are tracked for compatibility and docs generation
495purposes. For each version -- including `current` to represent the tip-of-tree
496version -- we record three different types of API surfaces.
497
498* `<version>.txt`: Public API surface, tracked for compatibility
499* `restricted_<version>.txt`: `@RestrictTo` API surface, tracked for
500 compatibility where necessary (see
501 [Restricted APIs](api_guidelines.md#restricted-api))
502* `public_plus_experimental_<version>.txt`: Public API surface plus
503 `@RequiresOptIn` experimental API surfaces used for documentation (see
504 [Experimental APIs](api_guidelines.md#experimental-api)) and API review
505
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000506### Release notes & the `Relnote:` tag {#relnote}
507
508Prior to releasing, release notes are pre-populated using a script and placed
509into a Google Doc. The Google Doc is manually double checked by library owners
510before the release goes live. To auto-populate your release notes, you can use
511the semi-optional commit tag `Relnote:` in your commit, which will automatically
512include that message the commit in the pre-populated release notes.
513
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000514The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000515
516#### How to use it?
517
518One-line release note:
519
520``` {.good}
521Relnote: Fixed a critical bug
522```
523
524``` {.good}
525Relnote: "Fixed a critical bug"
526```
527
528``` {.good}
529Relnote: Added the following string function: `myFoo(\"bar\")`
530```
531
532Multi-line release note:
533
534Note: If the following lines do not contain an indent, you may hit b/165570183.
535
536``` {.good}
537Relnote: "We're launching this awesome new feature! It solves a whole list of
538 problems that require a lot of explaining! "
539```
540
541``` {.good}
542Relnote: """Added the following string function: `myFoo("bar")`
543 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
544 """
545```
546
547Opt out of the Relnote tag:
548
549``` {.good}
550Relnote: N/A
551```
552
553``` {.good}
554Relnote: NA
555```
556
557NOT VALID:
558
559``` {.bad}
560Relnote: This is an INVALID multi-line release note. Our current scripts won't
561include anything beyond the first line. The script has no way of knowing when
562the release note actually stops.
563```
564
565``` {.bad}
566Relnote: This is an INVALID multi-line release note. "Quotes" need to be
567 escaped in order for them to be parsed properly.
568```
569
570### Common build errors
571
572#### Diagnosing build failures
573
574If you've encountered a build failure and you're not sure what is triggering it,
575then please run
576`./development/diagnose-build-failure/diagnose-build-failure.sh`.
577
578This script can categorize your build failure into one of the following
579categories:
580
581* The Gradle Daemon is saving state in memory and triggering a failure
582* Your source files have been changed and/or incompatible git commits have
583 been checked out
584* Some file in the out/ dir is triggering an error
585 * If this happens, diagnose-build-failure.sh should also identify which
586 file(s) specifically
587* The build is nondeterministic and/or affected by timestamps
588* The build via gradlew actually passes and this build failure is specific to
589 Android Studio
590
591Some more-specific build failures are listed below in this page.
592
593#### Out-of-date platform prebuilts
594
595Like a normal Android library developed in Android Studio, libraries within
596`androidx` are built against prebuilts of the platform SDK. These are checked in
597to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
598
599If you are developing against pre-release platform APIs in the internal
600`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
601the latest API changes.
602
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000603#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000604
605If Gradle cannot resolve a dependency listed in your `build.gradle`, you may
606need to import the corresponding artifact into `prebuilts/androidx/external`.
607Our workflow does not automatically download artifacts from the internet to
608facilitate reproducible builds even if remote artifacts are changed.
609
610You can download a dependency by running:
611
612```shell
613cd frameworks/support && ./development/importMaven/import_maven_artifacts.py -n 'someGroupId:someArtifactId:someVersion'
614```
615
616This will create a change within the `prebuilts/androidx/external` directory.
617Make sure to upload this change before or concurrently (ex. in the same Gerrit
618topic) with the dependent library code.
619
620Libraries typically reference dependencies using constants defined in
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000621[`Dependencies.kt`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt),
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000622so please update this file to include a constant for the version of the library
623that you have checked in. You will reference this constant in your library's
624`build.gradle` dependencies.
625
626#### Updating an existing dependency
627
628If an older version of a dependency prebuilt was already checked in, please
629manually remove it within the same CL that adds the new prebuilt. You will also
630need to update `Dependencies.kt` to reflect the version change.
631
632#### My gradle build fails with "Cannot invoke method getURLs() on null object"
633
634You're using Java 9's javac, possibly because you ran envsetup.sh from the
635platform build or specified Java 9 as the global default Java compiler. For the
636former, you can simply open a new shell and avoid running envsetup.sh. For the
637latter, we recommend you set Java 8 as the default compiler using sudo
638update-java-alternatives; however, if you must use Java 9 as the default then
639you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
640
641#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
642
643You probably need to update the prebuilt SDK used by the gradle build. If you
644are referencing new framework APIs, you will need to wait for the framework
645changes to land in an SDK build (or build it yourself) and then land in both
646prebuilts/fullsdk and prebuilts/sdk. See
647[Updating SDK prebuilts](playbook.md#prebuilts-fullsdk) for more information.
648
649#### How do I handle refactoring a framework API referenced from a library?
650
651Because AndroidX must compile against both the current framework and the latest
652SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
653will need to refactor in stages: Remove references to the target APIs from
654AndroidX Perform the refactoring in the framework Update the framework prebuilt
655SDK to incorporate changes in (2) Add references to the refactored APIs in
656AndroidX Update AndroidX prebuilts to incorporate changes in (4)
657
658## Testing {#testing}
659
660AndroidX libraries are expected to include unit or integration test coverage for
661100% of their public API surface. Additionally, all CLs must include a `Test:`
662stanza indicating which tests were used to verify correctness. Any CLs
663implementing bug fixes are expected to include new regression tests specific to
664the issue being fixed
665
666See the [Testing](testing.md) page for more resources on writing, running, and
667monitoring tests.
668
669### AVD Manager
670
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000671The Android Studio instance started by `./studiow` uses a custom SDK directory,
672which means any virtual devices created by a "standard" non-AndroidX instance of
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700673Android Studio will be *visible* from the `./studiow` instance but will be
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000674unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000675
676You can either use the `Download` button to download an extra copy of the SDK
AndroidX Core Teame1288a72021-09-03 12:30:13 -0700677artifacts *or* you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000678directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000679
680```shell
681# Using the default MacOS Android SDK directory...
682ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
683 ../../prebuilts/fullsdk-darwin/system-images
684```
685
686### Benchmarking {#testing-benchmarking}
687
688Libraries are encouraged to write and monitor performance benchmarks. See the
689[Benchmarking](benchmarking.md) page for more details.
690
691## Library snapshots {#snapshots}
692
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000693### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000694
695Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000696snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000697
698```groovy {highlight=context:[buildId]}
699allprojects {
700 repositories {
701 google()
702 jcenter()
703 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
704 }
705}
706```
707
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000708You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
709for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000710
711```groovy {highlight=context:SNAPSHOT}
712dependencies {
713 implementation "androidx.core:core:1.2.0-SNAPSHOT"
714}
715```
716
717### Where to find snapshots
718
719If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
720can find them on either our public-facing build server:
721
722`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
723
724or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
725
726`https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository` for a
727specific build ID
728
729`https://androidx.dev/snapshots/builds/latest/artifacts/repository` for
730tip-of-tree snapshots
731
732### Obtaining a build ID
733
734To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000735[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000736on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
737androidx.dev site.
738
739Note that if you are using androidx.dev, you may substitute `latest` for a build
740ID to use the last known good build.
741
742To manually find the last known good `build-id`, you have several options.
743
744#### Snapshots on androidx.dev
745
746[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
747usable builds.
748
749#### Programmatically via `jq`
750
751Install `jq`:
752
753```shell
754sudo apt-get install jq
755```
756
757```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000758ID=`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 +0000759 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
760```
761
762#### Android build server
763
764Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000765[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000766on ci.android.com.
767
768For `androidx-snapshot` target, wait for the green "last known good build"
769button to load and then click it to follow it to the build artifact URL.
770
771### Using in a Gradle build
772
773To make these artifacts visible to Gradle, you need to add it as a respository:
774
775```groovy
776allprojects {
777 repositories {
778 google()
779 maven {
780 // For all Jetpack libraries (including Compose)
781 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
782 }
783 }
784}
785```
786
787Note that the above requires you to know the `build-id` of the snapshots you
788want.
789
790#### Specifying dependencies
791
792All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
793to use a snapshot artifact, the version in your `build.gradle` will need to be
794updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
795
796For example, to use the `core:core:1.2.0-SHAPSHOT` snapshot, you would add the
797following to your `build.gradle`:
798
799```
800dependencies {
801 ...
802 implementation("androidx.core:core:1.2.0-SNAPSHOT")
803 ...
804}
805```
806
807## FAQ {#faq}
808
809### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
810
811If you're working on a new feature or bug fix in AndroidX, you may want to test
812your changes against another project to verify that the change makes sense in a
813real-world context or that a bug's specific repro case has been fixed.
814
815If you need to be absolutely sure that your test will exactly emulate the
816developer's experience, you can repeatedly build the AndroidX archive and
817rebuild your application. In this case, you will need to create a local build of
818AndroidX's local Maven repository artifact and install it in your Android SDK
819path.
820
821First, use the `createArchive` Gradle task to generate the local Maven
822repository artifact:
823
824```shell
825# Creates <path-to-checkout>/out/dist/sdk-repo-linux-m2repository-##.zip
826./gradlew createArchive
827```
828
829Next, take the ZIP output from this task and extract the contents to the Android
830SDK path that you are using for your alternate (non-AndroidX) version of Android
831Studio. For example, you may be using `~/Android/SDK/extras` if you are using
832the default Android Studio SDK for app development or
833`prebuilts/fullsdk-linux/extras` if you are using fullsdk for platform
834development.
835
836```shell
837# Creates or overwrites android/m2repository
838cd <path-to-sdk>/extras
839unzip <path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip
840```
841
842In the project's 'build.gradle' within 'repositories' notify studio of the
843location of m2repository:
844
845```groovy
846allprojects {
847 repositories {
848 ...
849 maven {
850 url "<path-to-sdk>/extras/m2repository"
851 }
852 }
853}
854```
855
856NOTE Gradle resolves dependencies in the order that the repositories are defined
857(if 2 repositories can resolve the same dependency, the first listed will do so
858and the second will not). Therefore, if the library you are testing has the same
859group, artifact, and version as one already published, you will want to list
860your custom maven repo first.
861
862Finally, in the dependencies section of your standalone project's `build.gradle`
863file, add or update the `implementation` entries to reflect the AndroidX modules
864that you would like to test. Example:
865
866```
867dependencies {
868 ...
869 implementation "androidx.appcompat:appcompat::1.0.0-alpha02"
870}
871```
872
873If you are testing your changes in the Android Platform code, you can replace
874the module you are testing
875`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
876module. We recommend only replacing the module you are modifying instead of the
877full m2repository to avoid version issues of other modules. You can either take
878the unzipped directory from
879`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
880`<path-to-checkout>/out/androidx/build/support_repo/` after buiding `androidx`.
881Here is an example of replacing the RecyclerView module:
882
883```shell
884$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
885rm -rf $TARGET;
886cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
887```
888
889Make sure the library versions are the same before and after replacement. Then
890you can build the Android platform code with the new `androidx` code.