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