blob: 5bd331bd54bec6cdad6dca5f41603b2325fcf979 [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
16You will need to install the `repo` tool, which is used for Git branch and
17commit management. If you want to learn more about `repo`, see the
18[Repo Command Reference](https://source.android.com/setup/develop/repo).
19
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
94[androidx-master-dev](https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev)
95branch 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
103#### Public master development branch {#source-checkout-master}
104
105All development should occur in this branch unless otherwise specified by the
106AndroidX Core team.
107
108The following command will check out the public master development branch:
109
110```shell
111mkdir androidx-master-dev && cd androidx-master-dev
112repo init -u https://android.googlesource.com/platform/manifest \
113 -b androidx-master-dev --partial-clone --clone-filter=blob:limit=10M
114repo 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
133## Explore source code from a browser {#code-search}
134
135`androidx-master-dev` has a publicly-accessible
136[code search](https://cs.android.com/androidx/platform/frameworks/support) that
137allows you to explore all of the source code in the repository. Links to this
138URL may be shared on public Buganizer and other external sites.
139
140We recommend setting up a custom search engine in Chrome as a faster (and
141publicly-accessible) alternative to `cs/`.
142
143### Custom search engine for `androidx-master-dev` {#custom-search-engine}
144
1451. Open `chrome://settings/searchEngines`
1461. Click the `Add` button
1471. Enter a name for your search engine, ex. "AndroidX Code Search"
1481. Enter a keyword, ex. "csa"
1491. Enter the following URL:
150 `https://cs.android.com/search?q=%s&ss=androidx%2Fplatform%2Fframeworks%2Fsupport`
1511. Click the `Add` button
152
153Now you can select the Chrome omnibox, type in `csa` and press tab, then enter a
154query to search for, e.g. `AppCompatButton file:appcompat`, and press the
155`Enter` key to get to the search result page.
156
157## Develop in Android Studio {#studio}
158
159Library development uses a curated version of Android Studio to ensure
160compatibility between various components of the development workflow.
161
162From the `frameworks/support` directory, you can use `ANDROIDX_PROJECTS=MAIN
163./gradlew studio` to automatically download and run the correct version of
164Studio to work on main set of androidx projects. `ANDROIDX_PROJECTS` has several
165other options like `ANDROIDX_PROJECTS=ALL` to open other subsets of the
166projects.
167[settings.gradle](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:settings.gradle)
168file in the repository has these options listed.
169
170```shell
171ANDROIDX_PROJECTS=MAIN ./gradlew studio
172```
173
174Next, open the `framework/support` project root from your checkout. If Studio
175asks you which SDK you would like to use, select `Use project SDK`. Importing
176projects may take a while, but once that finishes you can use Studio as you
177normally would for application or library development -- right-click on a test
178or sample to run or debug it, search through classes, and so on.
179
180If you see any errors (red underlines), click Gradle's elephant button in the
181toolbar ("Sync Project with Gradle Files") and they should resolve once the
182build completes.
183
184> NOTE: You should choose "Use project SDK" when prompted by Studio. If you
185> picked "Android Studio SDK" by mistake, don't panic! You can fix this by
186> opening `File > Project Structure > Platform Settings > SDKs` and manually
187> setting the Android SDK home path to
188> `<project-root>/prebuilts/fullsdk-<platform>`.
189
190> NOTE: If Android Studio's UI looks scaled up, ex. twice the size it should be,
191> you may need to add the following line to your `studio64.vmoptions` file using
192> `Help -> Edit Custom VM Options`:
193>
194> ```
195> -Dsun.java2d.uiScale.enabled=false
196> ```
197
198## Making changes {#changes}
199
200Similar to Android framework development, library developmnent should occur in
201CL-specific working branches. Use `repo` to create, upload, and abandon local
202branches. Use `git` to manage changes within a local branch.
203
204```shell
205cd path/to/checkout/frameworks/support/
206repo start my_branch_name .
207# make necessary code changes
208# use git to commit changes
209repo upload --cbr -t .
210```
211
212The `--cbr` switch automatically picks the current repo branch for upload. The
213`-t` switch sets the Gerrit topic to the branch name, e.g. `my-branch-name`.
214
215## Building {#building}
216
217### Modules and Maven artifacts {#modules-and-maven-artifacts}
218
219To build a specific module, use the module's `assemble` Gradle task. For
220example, if you are working on `core` module use:
221
222```shell
223./gradlew core:core:assemble
224```
225
226Use the `-Pandroidx.allWarningsAsErrors` to make warnings fail your build (same
227as presubmits):
228
229```shell
230./gradlew core:core:assemble -Pandroidx.allWarningsAsErrors
231```
232
233To build every module, run the Lint verifier, verify the public API surface, and
234generate the local Maven repository artifact, use the `createArchive` Gradle
235task:
236
237```shell
238./gradlew createArchive
239```
240
241To run the complete build task that our build servers use, use the
242`buildOnServer` Gradle task:
243
244```shell
245./gradlew buildOnServer
246```
247
248### Attaching a debugger to the build
249
250Gradle tasks, including building a module, may be run or debugged from Android
251Studio's `Gradle` pane by finding the task to be debugged -- for example,
252`androidx > androidx > appcompat > appcompat > build > assemble` --
253right-clicking on it, and then selecting `Debug...`.
254
255Note that debugging will not be available until Gradle sync has completed.
256
257## From the command line
258
259Tasks may also be debugged from the command line, which may be useful if
260`./gradlew studio` cannot run due to a Gradle task configuration issue.
261
2621. From the configurations dropdown in Studio, select "Edit Configurations".
2631. Click the plus in the top left to create a new "Remote" configuration. Give
264 it a name and hit "Ok".
2651. Set breakpoints.
2661. Run your task with added flags: `./gradlew <your_task_here>
267 -Dorg.gradle.debug=true --no-daemon`
2681. Hit the "Debug" button to the right of the configuration dropdown to attach
269 to the process.
270
271#### Troubleshooting the debugger
272
273If you get a "Connection refused" error, it's likely because a gradle daemon is
274still running on the port specified in the config, and you can fix this by
275killing the running gradle daemons:
276
277```shell
278./gradlew --stop
279```
280
281Note: This is described in more detail in this
282[Medium article](https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b).
283
284#### Attaching to an annotation processor
285
286Annotation processors run as part of the build, to debug them is similar to
287debugging the build.
288
289For a Java project:
290
291```shell
292./gradlew <your_project>:compileDebugJava --no-daemon --rerun-tasks -Dorg.gradle.debug=true
293```
294
295For a Kotlin project:
296
297```shell
298./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"
299```
300
301### Optional: Enabling internal menu in IntelliJ/Studio
302
303To enable tools such as `PSI tree` inside of IntelliJ/Studio to help debug
304Android Lint checks and Metalava, you can enable the
305[internal menu](https://www.jetbrains.org/intellij/sdk/docs/reference_guide/internal_actions/enabling_internal.html)
306which is typically used for plugin and IDE development.
307
308### Reference documentation {#docs}
309
310Our reference docs (Javadocs and KotlinDocs) are published to
311https://developer.android.com/reference/androidx/packages and may be built
312locally.
313
314NOTE `./gradlew tasks` always has the canonical task information! When in doubt,
315run `./gradlew tasks`
316
317#### Javadocs
318
319To build API reference docs for tip-of-tree Java source code, run the Gradle
320task:
321
322```
323./gradlew disttipOfTreeDocs
324```
325
326This will output docs in the zip file:
327`{androidx-master-dev}/out/dist/android-support-tipOfTree-docs-0.zip`, as well
328as in local html files that you can check from your browser:
329`{androidx-master-dev}/out/androidx/build/javadoc/tipOfTree/offline/reference/packages.html`
330
331#### KotlinDocs
332
333To build API reference docs for tip-of-tree Kotlin source code, run the Gradle
334task:
335
336```
337./gradlew distTipOfTreeDokkaDocs
338```
339
340This will output docs in the zip file:
341`{androidx-master-dev}/out/dist/dokkaTipOfTreeDocs-0.zip`
342
343#### Release docs
344
345To build API reference docs for published artifacts formatted for use on
346[d.android.com](http://d.android.com), run the Gradle command:
347
348```
349./gradlew distpublicDocs
350```
351
352This will create the artifact
353`{androidx-master-dev}/out/dist/android-support-public-docs-0.zip`. This command
354builds docs based on the version specified in
355`{androidx-master-dev-checkout}/frameworks/support/buildSrc/src/main/kotlin/androidx/build/PublishDocsRules.kt`
356and uses the prebuilt checked into
357`{androidx-master-dev-checkout}/prebuilts/androidx/internal/androidx/`. We
358colloquially refer to this two step process of (1) updating PublishDocsRules.kt
359and (2) checking in a prebuilt artifact into the prebuilts directory as
360[The Prebuilts Dance](releasing.md#the-prebuilts-danceâ„¢). So, to build javadocs
361that will be published to
362https://developer.android.com/reference/androidx/packages, both of these steps
363need to be completed.
364
365Once you done the above steps, Kotlin docs will also be generated, with the only
366difference being that we use the Gradle command:
367
368```
369./gradlew distPublicDokkaDocs
370```
371
372which generates the kotlin docs artifact
373`{androidx-master-dev}/out/dist/dokkaPublicDocs-0.zip`
374
375### Updating public APIs {#updating-public-apis}
376
377Public API tasks -- including tracking, linting, and verifying compatibility --
378are run under the following conditions based on the `androidx` configuration
379block, evaluated in order:
380
381* `runApiTasks=Yes` => yes
382* `runApiTasks=No` => no
383* `toolingProject=true` => no
384* `mavenVersion` or group version not set => no
385* Has an existing `api/` directory => yes
386* `publish=SNAPSHOT_AND_RELEASE` => yes
387* Otherwise, no
388
389If you make changes to tracked public APIs, you will need to acknowledge the
390changes by updating the `<component>/api/current.txt` and associated API files.
391This is handled automatically by the `updateApi` Gradle task:
392
393```shell
394# Run updateApi for all modules.
395./gradlew updateApi
396
397# Run updateApi for a single module, ex. appcompat-resources in group appcompat.
398./gradlew :appcompat:appcompat-resources:updateApi
399```
400
401If you change the public APIs without updating the API file, your module will
402still build **but** your CL will fail Treehugger presubmit checks.
403
404### Release notes & the `Relnote:` tag {#relnote}
405
406Prior to releasing, release notes are pre-populated using a script and placed
407into a Google Doc. The Google Doc is manually double checked by library owners
408before the release goes live. To auto-populate your release notes, you can use
409the semi-optional commit tag `Relnote:` in your commit, which will automatically
410include that message the commit in the pre-populated release notes.
411
412The presence of a `Relnote:` tag is required for API changes in
413`androidx-master-dev`.
414
415#### How to use it?
416
417One-line release note:
418
419``` {.good}
420Relnote: Fixed a critical bug
421```
422
423``` {.good}
424Relnote: "Fixed a critical bug"
425```
426
427``` {.good}
428Relnote: Added the following string function: `myFoo(\"bar\")`
429```
430
431Multi-line release note:
432
433Note: If the following lines do not contain an indent, you may hit b/165570183.
434
435``` {.good}
436Relnote: "We're launching this awesome new feature! It solves a whole list of
437 problems that require a lot of explaining! "
438```
439
440``` {.good}
441Relnote: """Added the following string function: `myFoo("bar")`
442 It will fix cases where you have to call `myFoo("baz").myBar("bar")`
443 """
444```
445
446Opt out of the Relnote tag:
447
448``` {.good}
449Relnote: N/A
450```
451
452``` {.good}
453Relnote: NA
454```
455
456NOT VALID:
457
458``` {.bad}
459Relnote: This is an INVALID multi-line release note. Our current scripts won't
460include anything beyond the first line. The script has no way of knowing when
461the release note actually stops.
462```
463
464``` {.bad}
465Relnote: This is an INVALID multi-line release note. "Quotes" need to be
466 escaped in order for them to be parsed properly.
467```
468
469### Common build errors
470
471#### Diagnosing build failures
472
473If you've encountered a build failure and you're not sure what is triggering it,
474then please run
475`./development/diagnose-build-failure/diagnose-build-failure.sh`.
476
477This script can categorize your build failure into one of the following
478categories:
479
480* The Gradle Daemon is saving state in memory and triggering a failure
481* Your source files have been changed and/or incompatible git commits have
482 been checked out
483* Some file in the out/ dir is triggering an error
484 * If this happens, diagnose-build-failure.sh should also identify which
485 file(s) specifically
486* The build is nondeterministic and/or affected by timestamps
487* The build via gradlew actually passes and this build failure is specific to
488 Android Studio
489
490Some more-specific build failures are listed below in this page.
491
492#### Out-of-date platform prebuilts
493
494Like a normal Android library developed in Android Studio, libraries within
495`androidx` are built against prebuilts of the platform SDK. These are checked in
496to the `prebuilts/fullsdk-darwin/platforms/<android-version>` directory.
497
498If you are developing against pre-release platform APIs in the internal
499`androidx-platform-dev` branch, you may need to update these prebuilts to obtain
500the latest API changes.
501
502### Missing external dependency
503
504If Gradle cannot resolve a dependency listed in your `build.gradle`, you may
505need to import the corresponding artifact into `prebuilts/androidx/external`.
506Our workflow does not automatically download artifacts from the internet to
507facilitate reproducible builds even if remote artifacts are changed.
508
509You can download a dependency by running:
510
511```shell
512cd frameworks/support && ./development/importMaven/import_maven_artifacts.py -n 'someGroupId:someArtifactId:someVersion'
513```
514
515This will create a change within the `prebuilts/androidx/external` directory.
516Make sure to upload this change before or concurrently (ex. in the same Gerrit
517topic) with the dependent library code.
518
519Libraries typically reference dependencies using constants defined in
520[`Dependencies.kt`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:buildSrc/src/main/kotlin/androidx/build/dependencies/Dependencies.kt),
521so please update this file to include a constant for the version of the library
522that you have checked in. You will reference this constant in your library's
523`build.gradle` dependencies.
524
525#### Updating an existing dependency
526
527If an older version of a dependency prebuilt was already checked in, please
528manually remove it within the same CL that adds the new prebuilt. You will also
529need to update `Dependencies.kt` to reflect the version change.
530
531#### My gradle build fails with "Cannot invoke method getURLs() on null object"
532
533You're using Java 9's javac, possibly because you ran envsetup.sh from the
534platform build or specified Java 9 as the global default Java compiler. For the
535former, you can simply open a new shell and avoid running envsetup.sh. For the
536latter, we recommend you set Java 8 as the default compiler using sudo
537update-java-alternatives; however, if you must use Java 9 as the default then
538you may alternatively set JAVA_HOME to the location of the Java 8 SDK.
539
540#### My gradle build fails with "error: cannot find symbol" after making framework-dependent changes.
541
542You probably need to update the prebuilt SDK used by the gradle build. If you
543are referencing new framework APIs, you will need to wait for the framework
544changes to land in an SDK build (or build it yourself) and then land in both
545prebuilts/fullsdk and prebuilts/sdk. See
546[Updating SDK prebuilts](playbook.md#prebuilts-fullsdk) for more information.
547
548#### How do I handle refactoring a framework API referenced from a library?
549
550Because AndroidX must compile against both the current framework and the latest
551SDK prebuilt, and because compiling the SDK prebuilt depends on AndroidX, you
552will need to refactor in stages: Remove references to the target APIs from
553AndroidX Perform the refactoring in the framework Update the framework prebuilt
554SDK to incorporate changes in (2) Add references to the refactored APIs in
555AndroidX Update AndroidX prebuilts to incorporate changes in (4)
556
557## Testing {#testing}
558
559AndroidX libraries are expected to include unit or integration test coverage for
560100% of their public API surface. Additionally, all CLs must include a `Test:`
561stanza indicating which tests were used to verify correctness. Any CLs
562implementing bug fixes are expected to include new regression tests specific to
563the issue being fixed
564
565See the [Testing](testing.md) page for more resources on writing, running, and
566monitoring tests.
567
568### AVD Manager
569
570The Android Studio instance started by `./gradlew studio` uses a custom SDK
571directory, which means any virtual devices created by a "standard" non-AndroidX
572instance of Android Studio will be _visible_ from the `./gradlew studio`
573instance but will be unable to locate the SDK artifacts -- they will display a
574`Download` button.
575
576You can either use the `Download` button to download an extra copy of the SDK
577artifacts _or_ you can set up a symlink to your "standard" non-AndroidX SDK
578directory to expose your existing artifacts to the `./gradlew studio` instance:
579
580```shell
581# Using the default MacOS Android SDK directory...
582ln -s /Users/$(whoami)/Library/Android/sdk/system-images \
583 ../../prebuilts/fullsdk-darwin/system-images
584```
585
586### Benchmarking {#testing-benchmarking}
587
588Libraries are encouraged to write and monitor performance benchmarks. See the
589[Benchmarking](benchmarking.md) page for more details.
590
591## Library snapshots {#snapshots}
592
593### Quick how to
594
595Add the following snippet to your build.gradle file, replacing `buildId` with a
596snapshot build Id.
597
598```groovy {highlight=context:[buildId]}
599allprojects {
600 repositories {
601 google()
602 jcenter()
603 maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' }
604 }
605}
606```
607
608You must define dependencies on artifacts using the SNAPSHOT version suffix, for
609example:
610
611```groovy {highlight=context:SNAPSHOT}
612dependencies {
613 implementation "androidx.core:core:1.2.0-SNAPSHOT"
614}
615```
616
617### Where to find snapshots
618
619If you want to use unreleased `SNAPSHOT` versions of `androidx` artifacts, you
620can find them on either our public-facing build server:
621
622`https://ci.android.com/builds/submitted/<build_id>/androidx_snapshot/latest`
623
624or on our slightly-more-convenient [androidx.dev](https://androidx.dev) site:
625
626`https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository` for a
627specific build ID
628
629`https://androidx.dev/snapshots/builds/latest/artifacts/repository` for
630tip-of-tree snapshots
631
632### Obtaining a build ID
633
634To browse build IDs, you can visit either
635[androidx-master-dev](https://ci.android.com/builds/branches/aosp-androidx-master-dev/grid?)
636on ci.android.com or [Snapshots](https://androidx.dev/snapshots/builds) on the
637androidx.dev site.
638
639Note that if you are using androidx.dev, you may substitute `latest` for a build
640ID to use the last known good build.
641
642To manually find the last known good `build-id`, you have several options.
643
644#### Snapshots on androidx.dev
645
646[Snapshots](https://androidx.dev/snapshots/builds) on androidx.dev only lists
647usable builds.
648
649#### Programmatically via `jq`
650
651Install `jq`:
652
653```shell
654sudo apt-get install jq
655```
656
657```shell
658ID=`curl -s "https://ci.android.com/builds/branches/aosp-androidx-master-dev/status.json" | jq ".targets[] | select(.ID==\"aosp-androidx-master-dev.androidx_snapshot\") | .last_known_good_build"` \
659 && echo https://ci.android.com/builds/submitted/"${ID:1:-1}"/androidx_snapshot/latest/raw/repository/
660```
661
662#### Android build server
663
664Go to
665[androidx-master-dev](https://ci.android.com/builds/branches/aosp-androidx-master-dev/grid?)
666on ci.android.com.
667
668For `androidx-snapshot` target, wait for the green "last known good build"
669button to load and then click it to follow it to the build artifact URL.
670
671### Using in a Gradle build
672
673To make these artifacts visible to Gradle, you need to add it as a respository:
674
675```groovy
676allprojects {
677 repositories {
678 google()
679 maven {
680 // For all Jetpack libraries (including Compose)
681 url 'https://androidx.dev/snapshots/builds/<build-id>/artifacts/repository'
682 }
683 }
684}
685```
686
687Note that the above requires you to know the `build-id` of the snapshots you
688want.
689
690#### Specifying dependencies
691
692All artifacts in the snapshot repository are versioned as `x.y.z-SNAPSHOT`. So
693to use a snapshot artifact, the version in your `build.gradle` will need to be
694updated to `androidx.<groupId>:<artifactId>:X.Y.Z-SNAPSHOT`
695
696For example, to use the `core:core:1.2.0-SHAPSHOT` snapshot, you would add the
697following to your `build.gradle`:
698
699```
700dependencies {
701 ...
702 implementation("androidx.core:core:1.2.0-SNAPSHOT")
703 ...
704}
705```
706
707## FAQ {#faq}
708
709### How do I test my change in a separate Android Studio project? {#faq-test-change-studio}
710
711If you're working on a new feature or bug fix in AndroidX, you may want to test
712your changes against another project to verify that the change makes sense in a
713real-world context or that a bug's specific repro case has been fixed.
714
715If you need to be absolutely sure that your test will exactly emulate the
716developer's experience, you can repeatedly build the AndroidX archive and
717rebuild your application. In this case, you will need to create a local build of
718AndroidX's local Maven repository artifact and install it in your Android SDK
719path.
720
721First, use the `createArchive` Gradle task to generate the local Maven
722repository artifact:
723
724```shell
725# Creates <path-to-checkout>/out/dist/sdk-repo-linux-m2repository-##.zip
726./gradlew createArchive
727```
728
729Next, take the ZIP output from this task and extract the contents to the Android
730SDK path that you are using for your alternate (non-AndroidX) version of Android
731Studio. For example, you may be using `~/Android/SDK/extras` if you are using
732the default Android Studio SDK for app development or
733`prebuilts/fullsdk-linux/extras` if you are using fullsdk for platform
734development.
735
736```shell
737# Creates or overwrites android/m2repository
738cd <path-to-sdk>/extras
739unzip <path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip
740```
741
742In the project's 'build.gradle' within 'repositories' notify studio of the
743location of m2repository:
744
745```groovy
746allprojects {
747 repositories {
748 ...
749 maven {
750 url "<path-to-sdk>/extras/m2repository"
751 }
752 }
753}
754```
755
756NOTE Gradle resolves dependencies in the order that the repositories are defined
757(if 2 repositories can resolve the same dependency, the first listed will do so
758and the second will not). Therefore, if the library you are testing has the same
759group, artifact, and version as one already published, you will want to list
760your custom maven repo first.
761
762Finally, in the dependencies section of your standalone project's `build.gradle`
763file, add or update the `implementation` entries to reflect the AndroidX modules
764that you would like to test. Example:
765
766```
767dependencies {
768 ...
769 implementation "androidx.appcompat:appcompat::1.0.0-alpha02"
770}
771```
772
773If you are testing your changes in the Android Platform code, you can replace
774the module you are testing
775`YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository` with your own
776module. We recommend only replacing the module you are modifying instead of the
777full m2repository to avoid version issues of other modules. You can either take
778the unzipped directory from
779`<path-to-checkout>/out/dist/top-of-tree-m2repository-##.zip`, or from
780`<path-to-checkout>/out/androidx/build/support_repo/` after buiding `androidx`.
781Here is an example of replacing the RecyclerView module:
782
783```shell
784$TARGET=YOUR_ANDROID_PATH/prebuilts/sdk/current/androidx/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07;
785rm -rf $TARGET;
786cp -a <path-to-sdk>/extras/m2repository/androidx/recyclerview/recyclerview/1.1.0-alpha07 $TARGET
787```
788
789Make sure the library versions are the same before and after replacement. Then
790you can build the Android platform code with the new `androidx` code.