Add Subversion Revision to the apk name

Dear Community ,
it is my first message to the community.
I need a help to rename the release apk file from default name to my customer name
example : “myapplication_r”+Subversion Revision+".apk"
So my problem is to get the Subversion Revision from SVN. So I have creade a method

def svnversionSVN() {
    description 'Get SVN revision number.'
    new ByteArrayOutputStream().withStream { os ->
        def result = exec {
            executable = 'svnversion'
            standardOutput = os
        }
        ext.revid = os.toString()
    }
    return svnversion.revid
}

Then I add the result of this method to my apk name :

 buildTypes {
        release {
            minifyEnabled false

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        def fileName = outputFile.name.replace('.apk', "myapplication_r"+svnversionSVN()+".apk")
                        output.outputFile = new File(outputFile.parent, fileName)
                    }

                }
            }
        }
        debug {
        }
    }

but it doesn’t work :frowning:
I have a problem “Error:(58, 0) Could not find property ‘svnversion’ on project ‘:app’.” when I sync Gradle

Any help please ?
I’m beginner with Gradle and ANdroid Studio

The error is a result of the return statement in your svnversionSNV() method. I’m not sure where you are expecting svnversion to come from. You could simplify this by simply removing the method definition altogether, and just placing the body of the method in the root of your build script (which would cause it to run at configuration time). You could then reference the svn id later via the revid property that you are creating.