Dude
Dude

Reputation: 1302

Gradle how to replace the obsolete 'variantOutput.getPackageLibrary()' with 'variant.getPackageLibraryProvider()'?

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].outputFileas 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?

Upvotes: 5

Views: 3460

Answers (1)

RandomActsOfCode
RandomActsOfCode

Reputation: 3285

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"
                }
            }
        }
    }
    ...
}

Upvotes: 1

Related Questions