【发布时间】:2016-02-15 11:20:33
【问题描述】:
更具体地说,我有一些构建配置:
signingConfigs {
debug {
keyAlias ''
keyPassword ''
storeFile file('')
}
release {
keyAlias ''
keyPassword ''
storeFile file('')
storePassword ''
}
}
....
defaultConfig {
applicationId ""
minSdkVersion 21
targetSdkVersion 23
versionCode code
}
我希望 gradle 在每次运行“发布”时自动增加代码版本。
到目前为止我所拥有的:
def code = 1;
//Get all the gradle task names being run
List<String> runTasks = gradle.startParameter.getTaskNames();
for (String item : runTasks) {
//Get the version.properties file. Its our custom file for storing a code version, please don't remove it
def versionPropsFile = file('version.properties')
def Properties versionProps = new Properties()
//This will prevent the gradle from exploding when there's no file yet created
if (versionPropsFile.exists())
versionProps.load(new FileInputStream(versionPropsFile))
//It will insert the "0" version in case the file does not exist
code = (versionProps['VERSION_CODE'] ?: "0").toInteger()
if (item.contains("release")) {
// If we're building up on Jenkins, increment the version strings
code++
versionProps['VERSION_CODE'] = code.toString()
//It will overwrite the file even if it doesn't exist
versionProps.store(versionPropsFile.newWriter(), null)
}
}
问题:
我似乎无法进入if (item.contains("release"))。它总是错误的,但我肯定看到 gradle 运行这个任务。如何修复它或至少在控制台中输出 gradle 正在运行的所有任务(它们的名称)?
【问题讨论】:
-
@k3b 感谢您指出这一点。这篇文章中接受的解决方案对我不起作用。让我再检查一次。
标签: android gradle android-gradle-plugin