I would like to access versionCode and versionName in defaultConfig from a gradle task. I am using the experimental gradle plugin. I tried model.android.defaultConfig.versio
Create method in your build.gradle
:
def getVersionCode = { ->
// calculate versionCode code or use hardcoded value
return 1
}
Use this method in defaultConfig
:
android {
defaultConfig {
versionCode getVersionCode()
}
}
Use the same method in your custom task:
task printVersions{
print "Version code is " + getVersionCode()
}
Alternative solution is to access versionCode
property directly:
task printVersions{
print "Version code is $project.android.defaultConfig.versionCode"
}
Create method in your build.gradle:
def getVersionCode = { ->
return 1
}
Use this method in defaultConfig:
android {
defaultConfig {
versionCode getVersionCode()
}
}
versionCode property can get like:
task printVersions{
print "Version code is ${project.android.defaultConfig.versionCode}"
}