From ab87755b20279bd45f30d861b86920327fc9fd7b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 13 Jun 2018 13:50:01 +0200 Subject: [PATCH] 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 --- .gitlab-ci.yml | 3 +++ app/build.gradle | 27 +-------------------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index eb4a4810a..a0c4d7c91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,6 +96,9 @@ deploy_nightly: - echo "${CI_PROJECT_PATH}-nightly" >> app/src/main/res/values/default_repos.xml - echo "${CI_PROJECT_URL}-nightly/raw/master/fdroid/repo" >> 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 diff --git a/app/build.gradle b/app/build.gradle index 71d48a067..18a37fea6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 } }