Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escaping . (dot) in gradle string

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.

like image 762
noob Avatar asked Oct 23 '25 15:10

noob


1 Answers

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"
like image 151
Sarthak Mittal Avatar answered Oct 26 '25 06:10

Sarthak Mittal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!