AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 1 | ## AndroidX policies and processes |
| 2 | |
| 3 | This document is intended to describe release policies that affect the workflow |
| 4 | of an engineer developing within the AndroidX libraries. It also describes the |
| 5 | process followed by a release engineer or TPM to take a development branch and |
| 6 | publish it as a release on Google Maven. |
| 7 | |
| 8 | Policies and processes automated via tooling are noted in |
| 9 | <span style="color:#bf9000;">yellow</span>. |
| 10 | |
| 11 | [TOC] |
| 12 | |
| 13 | ## Project directory structure {#directory-structure} |
| 14 | |
| 15 | Libraries developed in AndroidX follow a consistent project naming and directory |
| 16 | structure. |
| 17 | |
| 18 | Library groups should organize their modules into directories and module names |
| 19 | (in brackets) as: |
| 20 | |
| 21 | ``` |
| 22 | <feature-name>/ |
| 23 | <feature-name>-<sub-feature>/ [<feature-name>:<feature-name>-<sub-feature>] |
| 24 | integration-tests/ |
| 25 | testapp/ [<feature-name>:testapp] |
| 26 | testlib/ [<feature-name>:testlib] |
| 27 | samples/ [<feature-name>:samples] |
| 28 | ``` |
| 29 | |
| 30 | For example, the `room` library group's directory structure is: |
| 31 | |
| 32 | ``` |
| 33 | room/ |
| 34 | common/ [room:room-common] |
| 35 | ... |
| 36 | rxjava2/ [room:room-rxjava2] |
| 37 | testing/ [room:room-testing] |
| 38 | integration-tests/ |
| 39 | testapp/ [room:testapp] |
| 40 | testapp-kotlin/ [room:testapp-kotlin] |
| 41 | ``` |
| 42 | |
| 43 | ## Terminology {#terminology} |
| 44 | |
| 45 | **Artifact** |
| 46 | : Previously referred to as "a Support Library library." A library -- |
| 47 | typically Java or Android -- that maps to a single Maven artifact, ex. |
| 48 | `androidx.recyclerview:recyclerview`. An artifact is associated with a |
| 49 | single Android Studio module and a directory containing a `build.gradle` |
| 50 | configuration, resources, and source code. |
| 51 | |
| 52 | **API Council** |
| 53 | : A committee that reviews Android APIs, both platform and library, to ensure |
| 54 | they are consistent and follow the best-practices defined in our API |
| 55 | guidelines. |
| 56 | |
| 57 | **Semantic Versioning (SemVer)** |
| 58 | : A versioning standard developed by one of the co-founders of GitHub that is |
| 59 | understood by common dependency management systems, including Maven. In this |
| 60 | document, we are referring specifically to |
| 61 | [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html). |
| 62 | |
| 63 | ## Managing versions {#managing-versions} |
| 64 | |
| 65 | This section outlines the steps for a variety of common versioning-related |
| 66 | tasks. Artifact versions should **only** be modified by their owners as |
| 67 | specified in the artifact directory's `OWNERS` file. |
| 68 | |
| 69 | Artifact versions are specified in |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame^] | 70 | [`LibraryVersions.kt`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt). |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 71 | Versions are bound to your artifact in the `supportLibrary` block in your |
| 72 | artifact's `build.gradle` file. The `Version` class validates the version string |
| 73 | at build time. |
| 74 | |
| 75 | In the |
AndroidX Core Team | 408c27b | 2020-12-15 15:57:00 +0000 | [diff] [blame^] | 76 | [`LibraryVersions.kt`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt) |
AndroidX Core Team | 2e416b2 | 2020-12-03 22:58:07 +0000 | [diff] [blame] | 77 | file: |
| 78 | |
| 79 | ``` |
| 80 | object LibraryVersions { |
| 81 | val SNAZZY_ARTIFACT = Version("1.1.0-alpha03") |
| 82 | } |
| 83 | ``` |
| 84 | |
| 85 | In your artifact's `build.gradle` file: |
| 86 | |
| 87 | ``` |
| 88 | import androidx.build.LibraryVersions |
| 89 | |
| 90 | supportLibrary { |
| 91 | mavenVersion = LibraryVersions.SNAZZY_ARTIFACT |
| 92 | } |
| 93 | ``` |
| 94 | |
| 95 | #### Finalizing for release {#finalizing-for-release} |
| 96 | |
| 97 | When the artifact is ready for release, its versioned API file should be |
| 98 | finalized to ensure that the subsequent versioned release conforms to the |
| 99 | versioning policies. |
| 100 | |
| 101 | ``` |
| 102 | ./gradlew <module>:finalizeApi |
| 103 | ``` |
| 104 | |
| 105 | This will prevent any subsequent changes to the API surface until the artifact |
| 106 | version is updated. To update the artifact version and allow changes within the |
| 107 | semantic versioning contract, simply update the version string in the artifact's |
| 108 | `build.gradle` (see [Workflow](#workflow) introduction). |
| 109 | |
| 110 | To avoid breaking the development workflow, we recommend that API finalization |
| 111 | and version string updates be submitted as a single CL. |
| 112 | |
| 113 | ## Dependencies {#dependencies} |
| 114 | |
| 115 | Artifacts may depend on other artifacts within AndroidX as well as sanctioned |
| 116 | third-party libraries. |
| 117 | |
| 118 | ### Versioned artifacts {#versioned-artifacts} |
| 119 | |
| 120 | One of the most difficult aspects of independently-versioned releases is |
| 121 | maintaining compatibility with public artifacts. In a mono repo such as Google's |
| 122 | repository or Android Git at master revision, it's easy for an artifact to |
| 123 | accidentally gain a dependency on a feature that may not be released on the same |
| 124 | schedule. |
| 125 | |
| 126 | #### Pre-release dependencies {#pre-release-dependencies} |
| 127 | |
| 128 | Pre-release suffixes **must** propagate up the dependency tree. For example, if |
| 129 | your artifact has API-type dependencies on pre-release artifacts, ex. |
| 130 | `1.1.0-alpha01`, then your artifact must also carry the `alpha` suffix. If you |
| 131 | only have implementation-type dependencies, your artifact may carry either the |
| 132 | `alpha` or `beta` suffix. |
| 133 | |
| 134 | #### Pinned versions {#pinned-versions} |
| 135 | |
| 136 | To avoid issues with dependency versioning, consider pinning your artifact's |
| 137 | dependencies to the oldest version (available via local `maven_repo` or Google |
| 138 | Maven) that satisfies the artifact's API requirements. This will ensure that the |
| 139 | artifact's release schedule is not accidentally tied to that of another artifact |
| 140 | and will allow developers to use older libraries if desired. |
| 141 | |
| 142 | ``` |
| 143 | dependencies { |
| 144 | api("androidx.collection:collection:1.0.0") |
| 145 | ... |
| 146 | } |
| 147 | ``` |
| 148 | |
| 149 | Artifacts should be built and tested against both pinned and tip-of-tree |
| 150 | versions of their dependencies to ensure behavioral compatibility. |
| 151 | |
| 152 | #### Non-Pinned versions {#nonpinned-versions} |
| 153 | |
| 154 | Below is an example of a non-pinned dependency. It ties the artifact's release |
| 155 | schedule to that of the dependency artifact, because the dependency will need to |
| 156 | be released at the same time. |
| 157 | |
| 158 | ``` |
| 159 | dependencies { |
| 160 | api(project(":collection")) |
| 161 | ... |
| 162 | } |
| 163 | ``` |
| 164 | |
| 165 | ### Non-public APIs {#non-public-apis} |
| 166 | |
| 167 | Artifacts may depend on non-public (e.g. `@hide`) APIs exposed within their own |
| 168 | artifact or another artifact in the same `groupId`; however, cross-artifact |
| 169 | usages are subject to binary compatibility guarantees and |
| 170 | `@RestrictTo(Scope.LIBRARY_GROUP)` APIs must be tracked like public APIs. |
| 171 | |
| 172 | ``` |
| 173 | Dependency versioning policies are enforced at build time in the createArchive task. This task will ensure that pre-release version suffixes are propagated appropriately. |
| 174 | |
| 175 | Cross-artifact API usage policies are enforced by the checkApi and checkApiRelease tasks (see Life of a release). |
| 176 | ``` |
| 177 | |
| 178 | ### Third-party libraries {#third-party-libraries} |
| 179 | |
| 180 | Artifacts may depend on libraries developed outside of AndroidX; however, they |
| 181 | must conform to the following guidelines: |
| 182 | |
| 183 | * Prebuilt **must** be checked into Android Git with both Maven and Make |
| 184 | artifacts |
| 185 | * `prebuilts/maven_repo` is recommended if this dependency is only |
| 186 | intended for use with AndroidX artifacts, otherwise please use |
| 187 | `external` |
| 188 | * Prebuilt directory **must** contains an OWNERS file identifying one or more |
| 189 | individual owners (e.g. NOT a group alias) |
| 190 | * Library **must** be approved by legal |