variantOutput.getPackageApplication() is obsolete

Martin Zeitler picture Martin Zeitler · Jan 15, 2019 · Viewed 26.4k times · Source

with Gradle 4.10.1 and the Android Gradle plugin updated to 3.3.0, I get the following warning:

WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.

the line, with the surrounding context (which is assigning output file-names by build variant):

applicationVariants.all { variant ->
    variant.outputs.all { output ->

        if (variant.getBuildType().getName() in rootProject.archiveBuildTypes) {

            def buildType = variant.getBuildType().getName()
            if (variant.versionName != null) {

                def baseName = output.baseName.toLowerCase()
                String fileName = "${rootProject.name}_${variant.versionName}-${baseName}.apk"

                // this is the line:
                outputFileName = new File(output.outputFile.parent, fileName).getName()
            }
        }
    }
}

the migration guide isn't too helpful; while the variant.outputs.all might be at fault - just have no clue with what to replace that - and the migration guide refers to tasks and not to build variants. when disabling File → Settings → Experimental → Gradle → Only sync the active variant, I get even more deprecation warnings (the point is, that none of these methods are being called directly):

WARNING: API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'.
WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
WARNING: API 'variantOutput.getProcessManifest()' is obsolete and has been replaced with 'variantOutput.getProcessManifestProvider()'.
WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'.
WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'.
WARNING: API 'variant.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.
WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.

Q: how can these deprecation warnings be avoided by migration to the new API?

Answer

Martin Zeitler picture Martin Zeitler · Jan 18, 2019

variantOutput.getPackageApplication() is being caused by a changed variant API.

changing output.outputFile.parent to variant.getPackageApplicationProvider().get().outputs.files[1] is at least a temporary workaround.

source: @Selvin.


variant.getExternalNativeBuildTasks() is being caused by the io.fabric plugin.

the next version of the io.fabric plugin will use variant.getExternalNativeBuildProviders().

source: 116408637; the confirmation for a promised fix (1.28.1).


These are caused by com.google.gms.google-services:

  • registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

  • 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'

This blog post explains how to get rid of the com.google.gms.google-services plugin altogether, by adding the XML resources, which that plugin generates, eg. from build/generated/res/google-services/debug/values/values.xml into the regular debug/values/values.xml.


The most easy and the least effort might be:

buildscript {
    repositories {
        google()
        maven { url "https://maven.fabric.io/public" }
    }
    dependencies {
        //noinspection GradleDependency
        classpath "com.android.tools.build:gradle:3.2.1"
        classpath "io.fabric.tools:gradle:1.28.1"
    }
}

For debug information: ./gradlew -Pandroid.debug.obsoleteApi=true mobile:assembleDebug

None of these warnings changes the behavior in any way.