I have an Android library project with several flavours. I upload the aar files of these different flavours to a private repository using the 'maven-publish'
plugin. I've been using the variant.outputs[0].outputFile
as the value for the publishing.publications.artifact
parameter.
publishing.publications.create variant.flavorName, MavenPublication, {
groupId "$libraryGroupId.$variant.flavorName"
artifactId libraryArtifactId
version libraryVersion
artifact variant.outputs[0].outputFile
}
It's been working great, but I've recently updated the library's gradle plugin to com.android.tools.build:gradle:3.3.2
and get the following warning:
WARNING: API 'variantOutput.getPackageLibrary()' is obsolete and has been replaced with 'variant.getPackageLibraryProvider()'. It will be removed at the end of 2019. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variantOutput.getPackageLibrary(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
It's not an issue per se, as it still works, but I don't like this warning and as I've been cleaning things up in my build.gradle
, I thought I'd try to fix it.
I've tried a lot of different combinations, raking the internet to try to find info on how to obtain the aar from the package library provider. There is close to nothing available on the subject (which is really frustrating) but I did find this post which led me to try with:
variant.getPackageLibraryProvider().get()
This provides a com.android.build.gradle.tasks.BundleAar
which seems to be working when set as the artifact of the publication (artifact variant.getPackageLibraryProvider().get()
) and fixes the warning.
Is this the right way to fix this warning or will it backfire on me for some reason? Does anyone know where I could get more info about this?
Using the Gradle and Android Gradle Plugin sources as reference, I came up with the following and the warning is gone:
publishing {
publications {
android.libraryVariants.all { variant ->
if (variant.buildType.name == "release") {
aar(MavenPublication) {
artifact(variant.packageLibraryProvider.get().archivePath)
groupId = '<your group id>'
artifactId = "$project.name"
}
}
}
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With