1

I have just upgraded an Android project's build.gradle to use build version 3.3.0

com.android.tools.build:gradle:3.3.0

Doing so has created this warning:

WARNING: API 'variant.getAssemble()' is obsolete and has been replaced with 'variant.getAssembleProvider()'.
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 variant.getAssemble(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app

It is caused by this code in the app build.gradle:

android.applicationVariants.all { variant ->

    variant.assemble.doLast {
        variant.outputs.each { output ->
            def apk = variant.outputs[0].outputFile
            File versionInfo = new File(apk.parent, "versionInfo.properties")
            versionInfo.text = "versionCode=${android.defaultConfig.versionCode}\nversionName=${android.defaultConfig.versionName}"
            copy {
                from "${versionInfo}"
                into "$project.projectDir/temp_archive"
            }
        }
    }
}

I haven't been able to find where I can rewrite this to make the warning disappear. I tried to follow this Stack Overflow post, but didn't make any progress. Any suggestions would be greatly appreciated.

B-Ray
  • 473
  • 1
  • 12
  • 29

1 Answers1

3

I found a potential solution that has resolved the warning. Below is the code I am using. Leaving the question for now in case there is a better solution.

android.applicationVariants.all { variant ->

    variant.getAssembleProvider().get().doLast {
        variant.outputs.each { output ->
            def apk = variant.outputs[0].outputFile
            File versionInfo = new File(apk.parent, "versionInfo.properties")
            versionInfo.text = "versionCode=${android.defaultConfig.versionCode}\nversionName=${android.defaultConfig.versionName}"
            copy {
                from "${versionInfo}"
                into "$project.projectDir/temp_archive"
            }
        }
    }
}
B-Ray
  • 473
  • 1
  • 12
  • 29