更新时间:2022-06-21 01:38:35
创建方法在你的 build.gradle
:
def getVersionCode = { ->
// calculate versionCode code or use hardcoded value
return 1
}
在 defaultConfig
中使用此方法:
$ b
Use this method in defaultConfig
:
android {
defaultConfig {
versionCode getVersionCode()
}
}
在您的自定义任务中使用相同的方法:
Use the same method in your custom task:
task printVersions{
print "Version code is " + getVersionCode()
}
替代解决方案是访问 versionCode 属性:
Alternative solution is to access versionCode
property directly:
task printVersions{
print "Version code is $project.android.defaultConfig.versionCode"
}