I am trying to change the output file name when creating Android builds. Here's the code that I am using for this
applicationVariants.all { variant ->
variant.outputs.all {
def buildDate = getDate()
outputFileName = "$variant.applicationId-$buildDate-$variant.buildType.name"
}
}
It works fine, but the output file doesn't have the .apk extension. So I tried to add it by adding .apk in the end
outputFileName ="$variant.applicationId-$buildDate-$variant.buildType.name.apk"
Which obviously didn't work. It generated the following error -
No such property: apk for class: java.lang.String
Then I tried to add \\ before .apk which worked, but generated an extra \ before .apk. Same with \$. I can add a blank space before .apk, but the file name will have a space in it.
My classpath is set as -
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0'
So my question is how can I escape the dot character and just print it as it is.
What I think is happening, is that gradle is getting confused whether it is a complete name of your variable or a plain String.
One solution would be to wrap your variables inside curly braces, like so:
"${variant.buildType.name}.apk"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With