I am using the following simplified configuration in an Android application project.
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 20
versionCode 1
versionName "1.0.0"
applicationVariants.all { variant ->
def file = variant.outputFile
def fileName = file.name.replace(".apk", "-" + versionName + ".apk")
variant.outputFile = new File(file.parent, fileName)
}
}
}
Now that I updated the Gradle plug-in to v.0.13.0 and Gradle to v.2.1. the following warnings appear:
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.getOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
WARNING [Project: :MyApp] variant.setOutputFile() is deprecated.
Call it on one of variant.getOutputs() instead.
How can I rewrite the Groovy script to get rid of the deprecation warnings?
Android Plugin for Gradle 3.0.0
You can use like this
you can get more on the features and new changes in android documentation https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle
The complete code snippet looks like that one:
Building on the answer from Larry Schiefer you can change the script to something like this:
The build variant output API has changed in the latest Android Gradle plugin. It now allows multiple output files (or directories), which is why this method has been marked as deprecated. If you use
variant.outputs
instead, it will give you aCollection
you can then iterate over and get each output file. You'll have to verify the file object is non-null and that it matches your criteria (e.g. has a '.apk' extension.) Then you can create a newFile
object and add it to the output within the collection.