Issue
I want to generate output apk file using customized name. Eg. By default, android studio generates "app-debug.apk" file. But I want it to be - "MyAppName_myCurrentProdFlavour_vMyVersionName.apk" How to do this using build.gradle file of module
Solution
1. For changing app bundle name (.aab file):
in app module's build.gradle:
def dateFormat = new Date().format('ddMMMyy_HHmm')
defaultConfig {
applicationId "com.xyz"
minSdk 21
targetSdk 31
versionCode 3
versionName "1.0.2"
setProperty("archivesBaseName", "yourappname" + "_v" + versionName + "(" + versionCode + ")_"+dateFormat)
}
For example: if your app name is XYZ then the bundle name will generated with name: XYZ_v1.0.2(3)_28Jan22_1152-prod-release
where, yourappname is XYZ , versionName is 1.0.2 , versionCode is 3 , dateFormat is 28Jan22_1152 , and app flavorType and buildType is prod-release
2. For changing apk file name (.apk file)
in app module's build.gradle:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def name = "XYZ"
def SEP = "_"
def flavor = variant.productFlavors[0].name
def buildType = variant.buildType.name
def versionName = defaultConfig.versionName
def versionCode = defaultConfig.versionCode
def newApkName = name + SEP + "v" + versionName + SEP + flavor + SEP + buildType + SEP + "vc" + versionCode + SEP + dateFormat + ".apk"
output.outputFileName = newApkName
}
}
}
For example, if your app name is XYZ then this will generate APK file with following custom name: XYZ_v1.0.2_prod_release_vc3_28Jan22_1152
Note: You can change dateFormat as per your requirement, for apk name if you don't have productFlavours then remove all related references from the code given above.
Answered By - pravingaikwad07
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.