Created
September 5, 2019 07:27
-
-
Save piyush-malaviya/1652f8450675a0465e6c3c5d59ded149 to your computer and use it in GitHub Desktop.
Gradle Build Flavor and Output Name Source: https://stackoverflow.com/questions/18332474/how-to-set-versionname-in-apk-filename-using-gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
... | |
buildTypes { | |
release { | |
minifyEnabled true | |
... | |
} | |
debug { | |
minifyEnabled false | |
} | |
} | |
productFlavors { | |
prod { | |
applicationId "com.example.myproject" | |
versionCode 3 | |
versionName "1.2.0" | |
} | |
dev { | |
applicationId "com.example.myproject.dev" | |
versionCode 15 | |
versionName "1.3.6" | |
} | |
} | |
applicationVariants.all { variant -> | |
variant.outputs.all { output -> | |
def project = "myProject" | |
def SEP = "_" | |
def flavor = variant.productFlavors[0].name | |
def buildType = variant.variantData.variantConfiguration.buildType.name | |
def version = variant.versionName | |
def date = new Date(); | |
def formattedDate = date.format('ddMMyy_HHmm') | |
def newApkName = project + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk" | |
outputFileName = new File(newApkName) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
applicationVariants.all { variant -> | |
variant.outputs.each { output -> | |
output.outputFile = new File( | |
output.outputFile.parent, | |
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment