blob: f8dcafa0c3f7d5dd063021a3397aa595bfb05c9d [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
11public APIs, or [Policies and Processes](policies.md) for an overview of the
12constraints placed on changes.
13
14## Workstation setup {#setup}
15
AndroidX Core Team0db91f02021-05-06 22:45:18 +000016You will need to install the
17[`repo`](https://source.android.com/setup/develop#repo) tool, which is used for
18Git branch and commit management. If you want to learn more about `repo`, see
19the [Repo Command Reference](https://source.android.com/setup/develop/repo).
AndroidX Core Team2e416b22020-12-03 22:58:07 +000020
21### Linux and MacOS {#setup-linux-mac}
22
23First, download `repo` using `curl`.
24
25```shell
26test -d ~/bin || mkdir ~/bin
27curl https://storage.googleapis.com/git-repo-downloads/repo \
28 > ~/bin/repo && chmod 700 ~/bin/repo
29```
30
31Then, modify `~/.bash_profile` (if using `bash`) to ensure you can find local
32binaries from the command line.
33
34```shell
35export PATH=~/bin:$PATH
36```
37
38You will need to either start a new terminal session or run `source
39~/.bash_profile` to pick up the new path.
40
41If you encounter an SSL `CERTIFICATE_VERIFY_FAILED` error or warning about
42Python 2 being no longer supported, you will need to install Python 3 and alias
43your `repo` command to run with `python3`.
44
45```shell {.bad}
46repo: warning: Python 2 is no longer supported; Please upgrade to Python 3.6+.
47```
48
49```shell {.bad}
50Downloading Repo source from https://gerrit.googlesource.com/git-repo
51fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
52fatal: error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
53```
54
55First, install Python 3 from the [official website](https://www.python.org).
56Please read the "Important Information" displayed during installation for
57information about SSL/TLS certificate validation and the running the "Install
58Certificates.command".
59
60Next, open your `~/.bash_profile` and add the following lines to wrap the `repo`
61command:
62
63```shell
64# Force repo to run with Python3
65function repo() {
66 command python3 "$(which repo)" $@
67}
68```
69
70### Windows {#setup-win}
71
72Sorry, Windows is not a supported platform for AndroidX development.
73
74## Set up access control {#access}
75
76### Authenticate to AOSP Gerrit {#access-gerrit}
77
78Before you can upload changes, you will need to associate your Google
79credentials with the AOSP Gerrit code review system by signing in to
80[android-review.googlesource.com](https://android-review.googlesource.com) at
81least once using the account you will use to submit patches.
82
83Next, you will need to
84[set up authentication](https://android-review.googlesource.com/new-password).
85This will give you a shell command to update your local Git cookies, which will
86allow you to upload changes.
87
88Finally, you will need to accept the
89[CLA for new contributors](https://android-review.googlesource.com/settings/new-agreement).
90
91## Check out the source {#source}
92
93Like ChromeOS, Chromium, and the Android build system, we develop in the open as
94much as possible. All feature development occurs in the public
AndroidX Core Team408c27b2020-12-15 15:57:00 +000095[androidx-main](https://android.googlesource.com/platform/frameworks/support/+/androidx-main)
AndroidX Core Team2e416b22020-12-03 22:58:07 +000096branch of the Android Open Source Project.
97
98As of 2020/03/20, you will need about 38 GB for a fully-built checkout.
99
100### Synchronize the branch {#source-checkout}
101
102Use the following `repo` commands to check out your branch.
103
AndroidX Core Teamf5f77ab2021-01-05 10:56:15 -0500104#### Public main development branch {#androidx-main}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000105
106All development should occur in this branch unless otherwise specified by the
107AndroidX Core team.
108
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000109The following command will check out the public main development branch:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000110
111```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000112mkdir androidx-main && cd androidx-main
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000113repo init -u https://android.googlesource.com/platform/manifest \
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000114 -b androidx-main --partial-clone --clone-filter=blob:limit=10M
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000115repo sync -c -j8
116```
117
118NOTE On MacOS, if you receive an SSL error like `SSL: CERTIFICATE_VERIFY_FAILED`
119you may need to install Python3 and boot strap the SSL certificates in the
120included version of pip. You can execute `Install Certificates.command` under
121`/Applications/Python 3.6/` to do so.
122
123### Increase Git rename limit {#source-config}
124
125To ensure `git` can detect diffs and renames across significant changes (namely,
126the `androidx.*` package rename), we recommend that you set the following `git
127config` properties:
128
129```shell
130git config --global merge.renameLimit 999999
131git config --global diff.renameLimit 999999
132```
133
134## Explore source code from a browser {#code-search}
135
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000136`androidx-main` has a publicly-accessible
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000137[code search](https://cs.android.com/androidx/platform/frameworks/support) that
138allows you to explore all of the source code in the repository. Links to this
AndroidX Core Team37584142021-02-25 17:58:46 +0000139URL may be shared on the public issue tracked and other external sites.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000140
141We recommend setting up a custom search engine in Chrome as a faster (and
142publicly-accessible) alternative to `cs/`.
143
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000144### Custom search engine for `androidx-main` {#custom-search-engine}
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000145
1461. Open `chrome://settings/searchEngines`
1471. Click the `Add` button
1481. Enter a name for your search engine, ex. "AndroidX Code Search"
1491. Enter a keyword, ex. "csa"
1501. Enter the following URL:
151 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
1521. Click the `Add` button
153
154Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
155query to search for, e.g. `AppCompatButton file:appcompat`, and press the
156`Enter` key to get to the search result page.
157
158## Develop in Android Studio {#studio}
159
160Library development uses a curated version of Android Studio to ensure
161compatibility between various components of the development workflow.
162
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000163From the `frameworks/support` directory, you can use `./studiow m` (short for
164`ANDROIDX_PROJECTS=main ./gradlew studio`) to automatically download and run the
165correct version of Studio to work on the `main` set of androidx projects.
166[studiow](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:studiow)
167also supports several other arguments like `all` for other subsets of the
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000168projects.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000169
170Next, open the `framework/support` project root from your checkout. If Studio
171asks you which SDK you would like to use, select `Use project SDK`. Importing
172projects may take a while, but once that finishes you can use Studio as you
173normally would for application or library development -- right-click on a test
174or sample to run or debug it, search through classes, and so on.
175
176If you see any errors (red underlines), click Gradle's elephant button in the
177toolbar ("Sync Project with Gradle Files") and they should resolve once the
178build completes.
179
180> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
181> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
182> opening `File > Project Structure > Platform Settings > SDKs` and manually
183> setting the Android SDK home path to
184> `<project-root>/prebuilts/fullsdk-<platform>`.
185
186> NOTE: If Android Studio's UI looks scaled up, ex. twice the size it should be,
187> you may need to add the following line to your `studio64.vmoptions` file using
188> `Help -> Edit Custom VM Options`:
189>
190> ```
191> -Dsun.java2d.uiScale.enabled=false
192> ```
193
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000194If in the future you encounter unexpected errors in Studio and you want to check
195for the possibility it is due to some incorrect settings or other generated
196files, you can run `./studiow --clean main <project subset>` or `./studiow
197--reinstall <project subset>` to clean generated files or reinstall Studio.
198
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000199## Making changes {#changes}
200
AndroidX Core Team5c914c42021-02-08 17:22:57 +0000201Similar to Android framework development, library development should occur in
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000202CL-specific working branches. Use `repo` to create, upload, and abandon local
203branches. Use `git` to manage changes within a local branch.
204
205```shell
206cd path/to/checkout/frameworks/support/
207repo start my_branch_name .
208# make necessary code changes
209# use git to commit changes
210repo upload --cbr -t .
211```
212
213The `--cbr` switch automatically picks the current repo branch for upload. The
AndroidX Core Team0db91f02021-05-06 22:45:18 +0000214`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`. You
215can refer to the
216[Android documentation](https://source.android.com/setup/create/coding-tasks#workflow)
217for a high level overview of this basic workflow.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000218
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000219NOTE If you encounter issues with `repo upload`, consider running upload with
220trace enabled, e.g. `GIT_DAPPER_TRACE=1 repo --trace upload . --cbr -y`. These
221logs can be helpful for reporting issues to the team that manages our git
222servers.
223
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000224NOTE If `repo upload` or any `git` command hangs and causes your CPU usage to
225skyrocket (e.g. your laptop fan sounds like a jet engine), then you may be
226hitting a rare issue with Git-on-Borg and HTTP/2. You can force `git` and `repo`
227to use HTTP/1.1 with `git config --global http.version HTTP/1.1`.
228
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000229## Building {#building}
230
231### Modules and Maven artifacts {#modules-and-maven-artifacts}
232
233To build a specific module, use the module's `assemble` Gradle task. For
234example, if you are working on `core` module use:
235
236```shell
237./gradlew core:core:assemble
238```
239
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000240To make warnings fail your build (same as presubmit), use the `--strict` flag,
241which our gradlew expands into a few correctness-related flags including
242`-Pandroidx.allWarningsAsErrors`:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000243
244```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000245./gradlew core:core:assemble --strict
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000246```
247
248To build every module, run the Lint verifier, verify the public API surface, and
249generate the local Maven repository artifact, use the `createArchive` Gradle
250task:
251
252```shell
253./gradlew createArchive
254```
255
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000256To run the complete build task that our build servers use, use the corresponding
257shell script:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000258
259```shell
AndroidX Core Team03b4da32021-03-10 23:20:41 +0000260./busytown/androidx.sh
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000261```
262
263### Attaching a debugger to the build
264
265Gradle tasks, including building a module, may be run or debugged from Android
266Studio's `Gradle` pane by finding the task to be debugged -- for example,
267`androidx > androidx > appcompat > appcompat > build > assemble` --
268right-clicking on it, and then selecting `Debug...`.
269
270Note that debugging will not be available until Gradle sync has completed.
271
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000272#### From the command line
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000273
274Tasks may also be debugged from the command line, which may be useful if
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000275`./studiow` cannot run due to a Gradle task configuration issue.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000276
2771. From the configurations dropdown in Studio, select "Edit Configurations".
2781. Click the plus in the top left to create a new "Remote" configuration. Give
279 it a name and hit "Ok".
2801. Set breakpoints.
2811. Run your task with added flags: `./gradlew <your_task_here>
282 -Dorg.gradle.debug=true --no-daemon`
2831. Hit the "Debug" button to the right of the configuration dropdown to attach
284 to the process.
285
286#### Troubleshooting the debugger
287
288If you get a "Connection refused" error, it's likely because a gradle daemon is
289still running on the port specified in the config, and you can fix this by
290killing the running gradle daemons:
291
292```shell
293./gradlew --stop
294```
295
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000296NOTE This is described in more detail in this
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000297[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
298
299#### Attaching to an annotation processor
300
301Annotation processors run as part of the build, to debug them is similar to
302debugging the build.
303
304For a Java project:
305
306```shell
307./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
308```
309
310For a Kotlin project:
311
312```shell
313./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"
314```
315
316### Optional: Enabling internal menu in IntelliJ/Studio
317
318To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
319Android Lint checks and Metalava, you can enable the
320[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
321which is typically used for plugin and IDE development.
322
323### Reference documentation {#docs}
324
325Our reference docs (Javadocs and KotlinDocs) are published to
326https://developer.android.com/reference/androidx/packages and may be built
327locally.
328
329NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
330run `./gradlew tasks`
331
332#### Javadocs
333
334To build API reference docs for tip-of-tree Java source code, run the Gradle
335task:
336
337```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000338./gradlew doclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000339```
340
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000341To generate offline docs use '-PofflineDocs=true' parameter. Places the
342documentation in
343`{androidx-main}/out/dist/out/androidx/docs-tip-of-tree/build/javadoc`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000344
345#### KotlinDocs
346
347To build API reference docs for tip-of-tree Kotlin source code, run the Gradle
348task:
349
350```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000351./gradlew dokkaKotlinDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000352```
353
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000354Places the documentation in
355`{androidx-main}/out/dist/out/androidx/docs-tip-of-tree/build/dokkaKotlinDocs`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000356
357#### Release docs
358
359To build API reference docs for published artifacts formatted for use on
360[d.android.com](http://d.android.com), run the Gradle command:
361
362```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000363./gradlew zipDoclavaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000364```
365
366This will create the artifact
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000367`{androidx-main}/out/dist/doclava-public-docs-0.zip`. This command builds docs
368based on the version specified in
369`{androidx-main-checkout}/frameworks/support/buildSrc/src/main/kotlin/androidx/build/PublishDocsRules.kt`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000370and uses the prebuilt checked into
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000371`{androidx-main-checkout}/prebuilts/androidx/internal/androidx/`. We
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000372colloquially refer to this two step process of (1) updating
373`PublishDocsRules.kt` and (2) checking in a prebuilt artifact into the prebuilts
374directory as [The Prebuilts Dance](releasing_detailed.md#the-prebuilts-danceâ„¢).
375So, to build javadocs that will be published to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000376https://developer.android.com/reference/androidx/packages, both of these steps
377need to be completed.
378
379Once you done the above steps, Kotlin docs will also be generated, with the only
380difference being that we use the Gradle command:
381
382```
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000383./gradlew zipDokkaDocs
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000384```
385
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000386This will create the artifact `{androidx-main}/out/dist/dokka-public-docs-0.zip`
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000387
388### Updating public APIs {#updating-public-apis}
389
390Public API tasks -- including tracking, linting, and verifying compatibility --
391are run under the following conditions based on the `androidx` configuration
392block, evaluated in order:
393
394* `runApiTasks=Yes` => yes
395* `runApiTasks=No` => no
396* `toolingProject=true` => no
397* `mavenVersion` or group version not set => no
398* Has an existing `api/` directory => yes
399* `publish=SNAPSHOT_AND_RELEASE` => yes
400* Otherwise, no
401
402If you make changes to tracked public APIs, you will need to acknowledge the
403changes by updating the `<component>/api/current.txt` and associated API files.
404This is handled automatically by the `updateApi` Gradle task:
405
406```shell
407# Run updateApi for all modules.
408./gradlew updateApi
409
410# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
411./gradlew :appcompat:appcompat-resources:updateApi
412```
413
414If you change the public APIs without updating the API file, your module will
415still build **but** your CL will fail Treehugger presubmit checks.
416
417### Release notes & the `Relnote:` tag {#relnote}
418
419Prior to releasing, release notes are pre-populated using a script and placed
420into a Google Doc. The Google Doc is manually double checked by library owners
421before the release goes live. To auto-populate your release notes, you can use
422the semi-optional commit tag `Relnote:` in your commit, which will automatically
423include that message the commit in the pre-populated release notes.
424
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000425The presence of a `Relnote:` tag is required for API changes in `androidx-main`.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000426
427#### How to use it?
428
429One-line release note:
430
431``` {.good}
432Relnote: Fixed a critical bug
433```
434
435``` {.good}
436Relnote: "Fixed a critical bug"
437```
438
439``` {.good}
440Relnote: Added the following string function: `myFoo(\"bar\")`
441```
442
443Multi-line release note:
444
445Note: If the following lines do not contain an indent, you may hit b/165570183.
446
447``` {.good}
448Relnote: "We're launching this awesome new feature! It solves a whole list of
449 problems that require a lot of explaining! "
450```
451
452``` {.good}
453Relnote: """Added the following string function: `myFoo("bar")`
454 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
455 """
456```
457
458Opt out of the Relnote tag:
459
460``` {.good}
461Relnote: N/A
462```
463
464``` {.good}
465Relnote: NA
466```
467
468NOT VALID:
469
470``` {.bad}
471Relnote: This is an INVALID multi-line release note. Our current scripts won't
472include anything beyond the first line. The script has no way of knowing when
473the release note actually stops.
474```
475
476``` {.bad}
477Relnote: This is an INVALID multi-line release note. "Quotes" need to be
478 escaped in order for them to be parsed properly.
479```
480
481### Common build errors
482
483#### Diagnosing build failures
484
485If you've encountered a build failure and you're not sure what is triggering it,
486then please run
487`./development/diagnose-build-failure/diagnose-build-failure.sh`.
488
489This script can categorize your build failure into one of the following
490categories:
491
492* The Gradle Daemon is saving state in memory and triggering a failure
493* Your source files have been changed and/or incompatible git commits have
494 been checked out
495* Some file in the out/ dir is triggering an error
496 * If this happens, diagnose-build-failure.sh should also identify which
497 file(s) specifically
498* The build is nondeterministic and/or affected by timestamps
499* The build via gradlew actually passes and this build failure is specific to
500 Android Studio
501
502Some more-specific build failures are listed below in this page.
503
504#### Out-of-date platform prebuilts
505
506Like a normal Android library developed in Android Studio, libraries within
507`androidx` are built against prebuilts of the platform SDK. These are checked in
508to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
509
510If you are developing against pre-release platform APIs in the internal
511`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
512the latest API changes.
513
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000514#### Missing external dependency
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000515
516If Gradle cannot resolve a dependency listed in your `build.gradle`, you may
517need to import the corresponding artifact into `prebuilts/androidx/external`.
518Our workflow does not automatically download artifacts from the internet to
519facilitate reproducible builds even if remote artifacts are changed.
520
521You can download a dependency by running:
522
523```shell
524cd frameworks/support && ./development/importMaven/import_maven_artifacts.py -n 'someGroupId:someArtifactId:someVersion'
525```
526
527This will create a change within the `prebuilts/androidx/external` directory.
528Make sure to upload this change before or concurrently (ex. in the same Gerrit
529topic) with the dependent library code.
530
531Libraries typically reference dependencies using constants defined in
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000532[`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 +0000533so please update this file to include a constant for the version of the library
534that you have checked in. You will reference this constant in your library's
535`build.gradle` dependencies.
536
537#### Updating an existing dependency
538
539If an older version of a dependency prebuilt was already checked in, please
540manually remove it within the same CL that adds the new prebuilt. You will also
541need to update `Dependencies.kt` to reflect the version change.
542
543#### My gradle build fails with "Cannot invoke method getURLs() on null object"
544
545You're using Java 9's javac, possibly because you ran envsetup.sh from the
546platform build or specified Java 9 as the global default Java compiler. For the
547former, you can simply open a new shell and avoid running envsetup.sh. For the
548latter, we recommend you set Java 8 as the default compiler using sudo
549update-java-alternatives; however, if you must use Java 9 as the default then
550you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
551
552#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
553
554You probably need to update the prebuilt SDK used by the gradle build. If you
555are referencing new framework APIs, you will need to wait for the framework
556changes to land in an SDK build (or build it yourself) and then land in both
557prebuilts/fullsdk and prebuilts/sdk. See
558[Updating SDK prebuilts](playbook.md#prebuilts-fullsdk) for more information.
559
560#### How do I handle refactoring a framework API referenced from a library?
561
562Because AndroidX must compile against both the current framework and the latest
563SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
564will need to refactor in stages: Remove references to the target APIs from
565AndroidX Perform the refactoring in the framework Update the framework prebuilt
566SDK to incorporate changes in (2) Add references to the refactored APIs in
567AndroidX Update AndroidX prebuilts to incorporate changes in (4)
568
569## Testing {#testing}
570
571AndroidX libraries are expected to include unit or integration test coverage for
572100% of their public API surface. Additionally, all CLs must include a `Test:`
573stanza indicating which tests were used to verify correctness. Any CLs
574implementing bug fixes are expected to include new regression tests specific to
575the issue being fixed
576
577See the [Testing](testing.md) page for more resources on writing, running, and
578monitoring tests.
579
580### AVD Manager
581
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000582The Android Studio instance started by `./studiow` uses a custom SDK directory,
583which means any virtual devices created by a "standard" non-AndroidX instance of
584Android Studio will be _visible_ from the `./studiow` instance but will be
585unable to locate the SDK artifacts -- they will display a `Download` button.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000586
587You can either use the `Download` button to download an extra copy of the SDK
588artifacts _or_ you can set up a symlink to your "standard" non-AndroidX SDK
AndroidX Core Teamee1457a2021-02-25 16:13:10 +0000589directory to expose your existing artifacts to the `./studiow` instance:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000590
591```shell
592# Using the default MacOS Android SDK directory...
593ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
594 ../../prebuilts/fullsdk-darwin/system-images
595```
596
597### Benchmarking {#testing-benchmarking}
598
599Libraries are encouraged to write and monitor performance benchmarks. See the
600[Benchmarking](benchmarking.md) page for more details.
601
602## Library snapshots {#snapshots}
603
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000604### Quick how-to
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000605
606Add the following snippet to your build.gradle file, replacing `buildId` with a
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000607snapshot build ID.
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000608
609```groovy {highlight=context:[buildId]}
610allprojects {
611 repositories {
612 google()
613 jcenter()
614 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
615 }
616}
617```
618
AndroidX Core Teamee9c1aa2021-04-06 17:29:05 +0000619You must define dependencies on artifacts using the `SNAPSHOT` version suffix,
620for example:
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000621
622```groovy {highlight=context:SNAPSHOT}
623dependencies {
624 implementation "androidx.core:core:1.2.0-SNAPSHOT"
625}
626```
627
628### Where to find snapshots
629
630If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
631can find them on either our public-facing build server:
632
633`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
634
635or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
636
637`https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository` for a
638specific build ID
639
640`https://androidx.dev/snapshots/builds/latest/artifacts/repository` for
641tip-of-tree snapshots
642
643### Obtaining a build ID
644
645To browse build IDs, you can visit either
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000646[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000647on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
648androidx.dev site.
649
650Note that if you are using androidx.dev, you may substitute `latest` for a build
651ID to use the last known good build.
652
653To manually find the last known good `build-id`, you have several options.
654
655#### Snapshots on androidx.dev
656
657[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
658usable builds.
659
660#### Programmatically via `jq`
661
662Install `jq`:
663
664```shell
665sudo apt-get install jq
666```
667
668```shell
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000669ID=`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 +0000670 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
671```
672
673#### Android build server
674
675Go to
AndroidX Core Team408c27b2020-12-15 15:57:00 +0000676[androidx-main](https://ci.android.com/builds/branches/aosp-androidx-main/grid?)
AndroidX Core Team2e416b22020-12-03 22:58:07 +0000677on ci.android.com.
678
679For `androidx-snapshot` target, wait for the green "last known good build"
680button to load and then click it to follow it to the build artifact URL.
681
682### Using in a Gradle build
683
684To make these artifacts visible to Gradle, you need to add it as a respository:
685
686```groovy
687allprojects {
688 repositories {
689 google()
690 maven {
691 // For all Jetpack libraries (including Compose)
692 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
693 }
694 }
695}
696```
697
698Note that the above requires you to know the `build-id` of the snapshots you
699want.
700
701#### Specifying dependencies
702
703All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
704to use a snapshot artifact, the version in your `build.gradle` will need to be
705updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
706
707For example, to use the `core:core:1.2.0-SHAPSHOT` snapshot, you would add the
708following to your `build.gradle`:
709
710```
711dependencies {
712 ...
713 implementation("androidx.core:core:1.2.0-SNAPSHOT")
714 ...
715}
716```
717
718## FAQ {#faq}
719
720### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
721
722If you're working on a new feature or bug fix in AndroidX, you may want to test
723your changes against another project to verify that the change makes sense in a
724real-world context or that a bug's specific repro case has been fixed.
725
726If you need to be absolutely sure that your test will exactly emulate the
727developer's experience, you can repeatedly build the AndroidX archive and
728rebuild your application. In this case, you will need to create a local build of
729AndroidX's local Maven repository artifact and install it in your Android SDK
730path.
731
732First, use the `createArchive` Gradle task to generate the local Maven
733repository artifact:
734
735```shell
736# Creates <path-to-checkout>/out/dist/sdk-repo-linux-m2repository-##.zip
737./gradlew createArchive
738```
739
740Next, take the ZIP output from this task and extract the contents to the Android
741SDK path that you are using for your alternate (non-AndroidX) version of Android
742Studio. For example, you may be using `~/Android/SDK/extras` if you are using
743the default Android Studio SDK for app development or
744`prebuilts/fullsdk-linux/extras` if you are using fullsdk for platform
745development.
746
747```shell
748# Creates or overwrites android/m2repository
749cd <path-to-sdk>/extras
750unzip <path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip
751```
752
753In the project's 'build.gradle' within 'repositories' notify studio of the
754location of m2repository:
755
756```groovy
757allprojects {
758 repositories {
759 ...
760 maven {
761 url "<path-to-sdk>/extras/m2repository"
762 }
763 }
764}
765```
766
767NOTE Gradle resolves dependencies in the order that the repositories are defined
768(if 2 repositories can resolve the same dependency, the first listed will do so
769and the second will not). Therefore, if the library you are testing has the same
770group, artifact, and version as one already published, you will want to list
771your custom maven repo first.
772
773Finally, in the dependencies section of your standalone project's `build.gradle`
774file, add or update the `implementation` entries to reflect the AndroidX modules
775that you would like to test. Example:
776
777```
778dependencies {
779 ...
780 implementation "androidx.appcompat:appcompat::1.0.0-alpha02"
781}
782```
783
784If you are testing your changes in the Android Platform code, you can replace
785the module you are testing
786`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
787module. We recommend only replacing the module you are modifying instead of the
788full m2repository to avoid version issues of other modules. You can either take
789the unzipped directory from
790`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
791`<path-to-checkout>/out/androidx/build/support_repo/` after buiding `androidx`.
792Here is an example of replacing the RecyclerView module:
793
794```shell
795$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
796rm -rf $TARGET;
797cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
798```
799
800Make sure the library versions are the same before and after replacement. Then
801you can build the Android platform code with the new `androidx` code.