set versionCode for nightly builds only in gitlab-ci

Having dynamic build config variables breaks instant APK updates:
https://developer.android.com/studio/build/optimize-your-build#use_static_build_properties
This commit is contained in:
Hans-Christoph Steiner 2018-06-13 13:50:01 +02:00
parent 361281aa3b
commit ab87755b20
2 changed files with 4 additions and 26 deletions

View File

@ -96,6 +96,9 @@ deploy_nightly:
- echo "<item>${CI_PROJECT_PATH}-nightly</item>" >> app/src/main/res/values/default_repos.xml
- echo "<item>${CI_PROJECT_URL}-nightly/raw/master/fdroid/repo</item>" >> app/src/main/res/values/default_repos.xml
- cat config/nightly-repo/repo.xml >> app/src/main/res/values/default_repos.xml
- export DB=`sed -n 's,.*DB_VERSION *= *\([0-9][0-9]*\).*,\1,p' app/src/main/java/org/fdroid/fdroid/data/DBHelper.java`
- export versionCode=`printf '%d%05d' $DB $(date '+%s'| cut -b4-8)`
- sed -i "s,^\(\s*versionCode\) *[0-9].*,\1 $versionCode," app/build.gradle
# build the APKs!
- ./gradlew assembleDebug
- fdroid nightly -v

View File

@ -59,32 +59,7 @@ android {
applicationIdSuffix ".debug"
resValue "string", "applicationId", defaultConfig.applicationId + applicationIdSuffix
versionNameSuffix "-debug"
}
}
/* set the debug versionCode based on DB verson and how many commits in the repo */
applicationVariants.all { variant ->
if (variant.buildType.isDebuggable()) {
// default to a timestamp, in case anything fails later
variant.mergedFlavor.versionCode = new Date().getTime() / 1000
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--first-parent', '--count', 'HEAD'
standardOutput = stdout
}
def commitCount = Integer.parseInt(stdout.toString().trim())
stdout = new ByteArrayOutputStream()
exec {
commandLine 'sed', '-n', 's,.*DB_VERSION *= *\\([0-9][0-9]*\\).*,\\1,p', 'src/main/java/org/fdroid/fdroid/data/DBHelper.java'
standardOutput = stdout
}
def dbVersion = Integer.parseInt(stdout.toString().trim())
println 'Setting debug versionCode: ' + sprintf("%d%05d", [dbVersion, commitCount])
variant.mergedFlavor.versionCode = Integer.parseInt(sprintf("%d%05d", [dbVersion, commitCount]))
}
catch (ignored) {
}
println 'buildTypes.debug defaultConfig.versionCode ' + defaultConfig.versionCode
}
}