Add that code inside the buildTypes{ } section of your flavor. The sample code will look for the .apk substring in the filename and rename it by adding an underscore plus the version name of the app and the .apk suffix.