Publishing an AAR

The merged aar is included in a Gradle SoftwareComponent that you can publish using your plugin of choice. One component is created per library variant, using the same name as the variant.

Integrating publishing with common publishing plugins is very simple, but direct access to the generated aar file is also available if a custom publishing solution is needed.

maven-publish

https://docs.gradle.org/current/userguide/publishing_maven.html

afterEvaluate {
  publishing {
    publications {
      create<MavenPublication>("maven") {
        from(components["release"])
      }
    }
  }
}
afterEvaluate {
  publishing {
    publications {
      maven(MavenPublication) {
        from(components.release)
      }
    }
  }
}
com.vanniktech.maven.publish

https://github.com/vanniktech/gradle-maven-publish-plugin

You will need to specify the variant name of the merged aar you want to publish via a project property:

project.ext.set("ANDROID_VARIANT_TO_PUBLISH", "release")
Custom Publishing

If you have your own custom publishing step, you can reference the generated aar file as a property like so:

abstract class MyCustomPublishTask {
  @get:InputFile
  abstract val inputJar: RegularFileProperty

  // ...
}

tasks.named<MyCustomPublishTask>("publish") {
  inputAar.set(tasks.named<PackageAarTask>("packageReleaseAar").flatMap { it.outputAar })
}
abstract class MyCustomPublishTask {
  @InputFile
  abstract RegularFileProperty inputJar;

  // ...
}

tasks.named("publish", MyCustomPublishTask).configureEach {
  inputAar.set(tasks.named("packageReleaseAar", PackageAarTask).flatMap { it.outputAar })
}

If using Android Gradle Plugin 8.0 or higher, make sure you've also set up variant publishing. Consult with the variant publication documentation if you need additional customization.

android {
  publishing {
    singleVariant("release")
  }
}
android {
  publishing {
    singleVariant "release"
  }
}