Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle warning: variant.getOutputFile() and variant.setOutputFile() are deprecated

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?

like image 531
JJD Avatar asked Sep 23 '14 14:09

JJD


People also ask

How do I change the Gradle wrapper version?

Method 1. Then just click on Build, Execution, Deployment Tab Build → Tools → Gradle → Use default Gradle wrapper (recommended) option. Step 2: Selecting desired Gradle version. Then click on the Project option.

Which gradle version should I use?

A Java version between 8 and 18 is required to execute Gradle. Java 19 and later versions are not yet supported. Java 6 and 7 can still be used for compilation and forked test execution.


1 Answers

Building on the answer from Larry Schiefer you can change the script to something like this:

android {     applicationVariants.all { variant ->         variant.outputs.each { output ->             def outputFile = output.outputFile             if (outputFile != null && outputFile.name.endsWith('.apk')) {                 def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")                 output.outputFile = new File(outputFile.parent, fileName)             }         }     } } 
like image 66
Thorbear Avatar answered Sep 25 '22 23:09

Thorbear