In particolare ho alcune configurazioni di build:Come posso implementare l'auto increrement della versione con codice gradle?
signingConfigs {
debug {
keyAlias ''
keyPassword ''
storeFile file('')
}
release {
keyAlias ''
keyPassword ''
storeFile file('')
storePassword ''
}
}
....
defaultConfig {
applicationId ""
minSdkVersion 21
targetSdkVersion 23
versionCode code
}
Voglio che il Gradle a AutoIncrement versione del codice ogni volta che viene eseguito il 'rilascio'.
Quello che ho finora:
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)
}
}
Il problema:
non riesco a entrare if (item.contains("release"))
. È sempre falso, ma sicuramente vedo che gradle gestisce questo taks. Come posso risolvere il problema o almeno produrre in console tutte le attività (i loro nomi) gestite da gradle?
è un duplicato di http://stackoverflow.com/questions/23516090/android-studio-gradle-version-increment?rq=1? – k3b
@ k3b grazie per aver indicato questo. La soluzione accettata in questo post non funziona per me. Fammi controllare ancora una volta. –