how append date build to versionNameSuffix on gradle
Also, do not forget to add import as Gradle first line:
import java.text.SimpleDateFormat;
...
beta {
packageNameSuffix ".beta"
versionNameSuffix "-beta" + "-build" + getDate()
signingConfig signingConfigs.debug
}
def getDate() {
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmmss')
return formattedDate
}
Condensed:
def getDate() {
return new Date().format('yyyyMMddHHmmss')
}
for simple one row solution define this property above android section
final BUILD_DATE = new Date().format('yyyy_MM_dd_HHmm')
and then
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.compileSdkVersion
versionName GIT_TAG_NAME
versionCode GIT_COMMIT_COUNT
setProperty("archivesBaseName",`enter code here` "com-appname-$BUILD_DATE-$versionName")
}
}
You can define in your build.gradle custom functions and variables.
def versionMajor = 3
def buildTime() {
def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") // you can change it
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(new Date())
}
Then you can use it:
android {
defaultConfig {
versionName "${versionMajor}-beta-build-${buildTime()}"
}
}
or if you want to add it in you versionNameSuffix
beta {
versionNameSuffix "-beta-build-${buildTime()}"
}