We have an Android project which uses Android Gradle Plugin 7.X and relies on multiple build variants to publish both .apks and .aabs initially to our Maven repository and on demand to Play Store. The build variants are combined using the productFlavor name and buildConfig options, and the result is something like brand1-release, or brand2-debug.
When we publish the resources to Maven, we rely on the components.build-name-of-variant with the following code:
afterEvaluate {
publishing {
publications {
brand1Apk(MavenPublication) {
groupId = 'apk.release.' + brand1
artifactId = 'brand1'
from components.**brand1Release_apk**
}
...
}
}
Now, with AGP 7 everything works OK, but I noticed this warning
WARNING: Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the gradle.properties file or use the new publishing DSL.
After upgrading to AGP 8, the publishing breaks because, as expected, the software component , the brand1Release_apk part of components.brand1Release_apk , is not created automatically.
And this is where my confusion starts.
I found this thread Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0 which points to a nice direction about using singleVariant('release') {} and multipleVariants {} but reading through the documentation for ApplicationPublishing and Configure publication variants and LibraryPublishing I get the feeling that these options are more reserved for publishing libraries. Also, the thread above mentions the 'com.android.library' plugin and in my case I have all of the above mentioned under the main module of the app which of course uses the com.android.application plugin.
Is there are a brave soul to shed some lights on these Gradle conundrums? How can I use the components associated with the build variants in the MavenPublications task under AGP 8?