Stay organized with collections
Save and categorize content based on your preferences.
LibraryPublishing
interface LibraryPublishing : Publishing<LibrarySingleVariant>
Maven publishing DSL object for configuring options related to publishing AAR.
To publish just one variant, use singleVariant. The following sets up publishing of only the
fullRelease variant of an android library.
android {
// This project has four build variants: fullDebug, fullRelease, demoDebug, demoRelease
flavorDimensions 'mode'
productFlavors {
full {}
demo {}
}
publishing {
// Publishes "fullRelease" build variant with "fullRelease" component created by
// Android Gradle plugin
singleVariant("fullRelease")
}
}
afterEvaluate {
publishing {
publications {
fullRelease(MavenPublication) {
from components.fullRelease
// ......
}
}
}
}
To publish multiple variants, use multipleVariants. The following sets up publishing of both
fullDebug and fullRelease variants of an android library.
android {
publishing {
// Published fullDebug and fullRelease build variants with "full" component created by
// Android Gradle Plugin. The buildType attribute is added to published build variants.
// As only a single flavor from "mode" dimension is included, no flavor attribute is
// included.
multipleVariants("full") {
includeBuildTypeValues("debug", "release")
includeFlavorDimensionAndValues("mode", "full")
}
}
}
afterEvaluate {
publishing {
publications {
full(MavenPublication) {
from components.full
// ......
}
}
}
}
To publish all the build variants, you can use MultipleVariants.allVariants as a shortcut
instead of filtering variants with MultipleVariants.includeBuildTypeValues
and MultipleVariants.includeFlavorDimensionAndValues.
android {
publishing {
// Publishes all build variants with "default" component
multipleVariants {
allVariants()
}
}
}
afterEvaluate {
publishing {
publications {
allVariants(MavenPublication) {
from components.default
// ......
}
}
}
}
This following code example shows how to create two publications one for demoRelease build
variant, one for fullDebug & fullRelease build variants.
android {
publishing {
// Publish "demoRelease" build variant with "demoRelease" component
singleVariant("demoRelease")
// Publish "fullDebug" and "fullRelease" build variants with "full" component
multipleVariants("full") {
includeBuildTypeValues("debug", "release")
includeFlavorDimensionAndValues("mode", "full")
}
}
}
afterEvaluate {
publishing {
publications {
// Creates two publications with different artifactIds
full(MavenPublication) {
from components.full
groupId = 'com.example.MyLibrary'
artifactId = 'final-full'
version = '1.0'
}
demoRelease(MavenPublication) {
from components.demoRelease
groupId = 'com.example.MyLibrary'
artifactId = 'final-demo'
version = '1.0'
}
}
}
}
The testFixtures component is published by default with its main variant. To disable publishing
the testFixtures component, see the following example.
afterEvaluate {
// Disable publishing test fixtures of release variant
components.release.withVariantsFromConfiguration(
configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }
components.release.withVariantsFromConfiguration(
configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }
}
Summary
Public methods
|
abstract Unit |
Publish multiple variants to a component.
|
abstract Unit |
Publish multiple variants to the default component.
|
Public methods
multipleVariants
abstract fun multipleVariants(
componentName: String,
action: MultipleVariants.() -> Unit
): Unit
Publish multiple variants to a component.
multipleVariants
abstract fun multipleVariants(action: MultipleVariants.() -> Unit): Unit
Publish multiple variants to the default component.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# LibraryPublishing\n=================\n\n```\ninterface LibraryPublishing : Publishing\u003cLibrarySingleVariant\u003e\n```\n\n|--------------------------------------------------|\n| [com.android.build.api.dsl.LibraryPublishing](#) |\n\nMaven publishing DSL object for configuring options related to publishing AAR.\n\nTo publish just one variant, use [singleVariant](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Publishing#singleVariant(kotlin.String)). The following sets up publishing of only the\nfullRelease variant of an android library. \n\n```gdscript\nandroid {\n // This project has four build variants: fullDebug, fullRelease, demoDebug, demoRelease\n flavorDimensions 'mode'\n productFlavors {\n full {}\n demo {}\n }\n\n publishing {\n // Publishes \"fullRelease\" build variant with \"fullRelease\" component created by\n // Android Gradle plugin\n singleVariant(\"fullRelease\")\n }\n}\n\nafterEvaluate {\n publishing {\n publications {\n fullRelease(MavenPublication) {\n from components.fullRelease\n // ......\n }\n }\n }\n}\n```\n\nTo publish multiple variants, use [multipleVariants](#multipleVariants(kotlin.String,%20kotlin.Function1)). The following sets up publishing of both\nfullDebug and fullRelease variants of an android library. \n\n```gdscript\nandroid {\n publishing {\n // Published fullDebug and fullRelease build variants with \"full\" component created by\n // Android Gradle Plugin. The buildType attribute is added to published build variants.\n // As only a single flavor from \"mode\" dimension is included, no flavor attribute is\n // included.\n multipleVariants(\"full\") {\n includeBuildTypeValues(\"debug\", \"release\")\n includeFlavorDimensionAndValues(\"mode\", \"full\")\n }\n }\n}\n\nafterEvaluate {\n publishing {\n publications {\n full(MavenPublication) {\n from components.full\n // ......\n }\n }\n }\n}\n```\n\nTo publish all the build variants, you can use [MultipleVariants.allVariants](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/MultipleVariants#allVariants()) as a shortcut\ninstead of filtering variants with [MultipleVariants.includeBuildTypeValues](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/MultipleVariants#includeBuildTypeValues(kotlin.String))\nand [MultipleVariants.includeFlavorDimensionAndValues](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/MultipleVariants#includeFlavorDimensionAndValues(kotlin.String,%20kotlin.String)). \n\n```gdscript\nandroid {\n publishing {\n // Publishes all build variants with \"default\" component\n multipleVariants {\n allVariants()\n }\n }\n}\n\nafterEvaluate {\n publishing {\n publications {\n allVariants(MavenPublication) {\n from components.default\n // ......\n }\n }\n }\n}\n```\n\nThis following code example shows how to create two publications one for demoRelease build\nvariant, one for fullDebug \\& fullRelease build variants. \n\n```gdscript\nandroid {\n publishing {\n // Publish \"demoRelease\" build variant with \"demoRelease\" component\n singleVariant(\"demoRelease\")\n\n // Publish \"fullDebug\" and \"fullRelease\" build variants with \"full\" component\n multipleVariants(\"full\") {\n includeBuildTypeValues(\"debug\", \"release\")\n includeFlavorDimensionAndValues(\"mode\", \"full\")\n }\n }\n}\n\nafterEvaluate {\n publishing {\n publications {\n // Creates two publications with different artifactIds\n full(MavenPublication) {\n from components.full\n groupId = 'com.example.MyLibrary'\n artifactId = 'final-full'\n version = '1.0'\n }\n demoRelease(MavenPublication) {\n from components.demoRelease\n groupId = 'com.example.MyLibrary'\n artifactId = 'final-demo'\n version = '1.0'\n }\n }\n }\n}\n```\n\nThe testFixtures component is published by default with its main variant. To disable publishing\nthe testFixtures component, see the following example. \n\n```gdscript\nafterEvaluate {\n // Disable publishing test fixtures of release variant\n components.release.withVariantsFromConfiguration(\n configurations.releaseTestFixturesVariantReleaseApiPublication) { skip() }\n components.release.withVariantsFromConfiguration(\n configurations.releaseTestFixturesVariantReleaseRuntimePublication) { skip() }\n}\n```\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [multipleVariants](#multipleVariants(kotlin.String,%20kotlin.Function1))`(`componentName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `action:` `[MultipleVariants](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/MultipleVariants).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Publish multiple variants to a component. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [multipleVariants](#multipleVariants(kotlin.Function1))`(`action:` `[MultipleVariants](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/MultipleVariants).()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Publish multiple variants to the default component. |\n\n| ### Inherited functions ||\n|---|---|\n| From class [Publishing](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Publishing) |------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [singleVariant](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Publishing#singleVariant(kotlin.String))`(`variantName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` Publish a variant with single variant publishing mechanism. \u003cbr /\u003e | | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [singleVariant](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Publishing#singleVariant(kotlin.String,%20kotlin.Function1))`(`variantName:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `action:` `SingleVariantT.()` `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Publish a variant with single variant publishing options. \u003cbr /\u003e | ||\n\nPublic methods\n--------------\n\n### multipleVariants\n\n```\nabstract fun multipleVariants(\n componentName: String, \n action: MultipleVariants.() -\u003e Unit\n): Unit\n```\n\nPublish multiple variants to a component. \n\n### multipleVariants\n\n```\nabstract fun multipleVariants(action: MultipleVariants.() -\u003e Unit): Unit\n```\n\nPublish multiple variants to the default component."]]