When I use Android Studio 3.0 and I use the next version of Android Gradle Plugin in project/build.gradle:
cl
Assemble/concatenate your new file name:
def newFileName = "assemble-your-new-file-name"
Then, simply assign it back.
outputFileName = newFileName
More specifically is as following
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
// Redirect your apks to new defined location to outputDirPath
def outputDirPath = new File("${project.rootDir.absolutePath}/apks/${variant.flavorName}/${variant.buildType.name}")
variant.packageApplicationProvider.get().outputDirectory = outputDirPath
def apkFileName = "${rootProject.name}_${android.defaultConfig.versionName}.apk"
output.outputFileName = apkFileName // directly assign the new name back to outputFileName
}
}