From 5f26a785278ce34c2d170a80e7b8fde50de0437f Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 25 Oct 2017 22:15:40 +0200 Subject: [PATCH] auto-disable preDexLibraries on CI systems preDexing helps repeat builds run faster, but slows down builds that do not have any caching. CI builds start from scratch each time. Turns out that GitLab CI, Travis CI, Circle CI, and probably many others all define the "CI" environment variable, so its easy to detect when running in a CI environment. This makes things a lot cleaner. * https://docs.gitlab.com/ce/ci/variables/README.html * https://docs.travis-ci.com/user/environment-variables/ * https://circleci.com/docs/2.0/env-vars/ * https://github.com/codepath/android_guides/wiki/Setting-up-Travis-CI * https://stackoverflow.com/questions/23137764/building-a-debug-apk --- .gitlab-ci.yml | 18 +++++++++--------- app/build.gradle | 10 ++++++++++ build.gradle | 16 ---------------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 777c0a357..5dae6e6e4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,13 +22,13 @@ test: - ./tools/remove-unused-and-blank-translations.py - echo "These are unused or blank translations that should be removed:" - git --no-pager diff --exit-code || export EXITVALUE=1 - - ./gradlew assemble -PdisablePreDex + - ./gradlew assemble # always report on lint errors to the build log - sed -i -e 's,textReport .*,textReport true,' app/build.gradle - - ./gradlew lint -PdisablePreDex - - ./gradlew pmd -PdisablePreDex - - ./gradlew checkstyle -PdisablePreDex - - ./gradlew test -PdisablePreDex || { + - ./gradlew lint + - ./gradlew pmd + - ./gradlew checkstyle + - ./gradlew test || { for log in app/build/reports/*ests/*/*ml; do echo "read $log here:"; (cat "$log" | curl --silent -F 'clbin=<-' https://clbin.com) || true; @@ -42,12 +42,12 @@ connected10: variables: AVD_SDK: "10" script: - - ./gradlew assembleDebug -PdisablePreDex + - ./gradlew assembleDebug - emulator64-arm -avd fcl-test-$AVD_SDK -no-skin -no-audio -no-window & - ./tools/wait-for-emulator - adb shell input keyevent 82 & - export EXITVALUE=0 - - ./gradlew connectedCheck -PdisablePreDex || { + - ./gradlew connectedCheck || { adb -e logcat -d '*:E'; echo "get the full logcat here:"; (adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true; @@ -64,14 +64,14 @@ connected24: variables: AVD_SDK: "24" script: - - ./gradlew assembleDebug -PdisablePreDex + - ./gradlew assembleDebug - android list avd - emulator64-arm -avd fcl-test-$AVD_SDK -no-audio -no-window & - ./tools/wait-for-emulator - adb shell input keyevent 82 & - adb devices - export EXITVALUE=0 - - ./gradlew connectedCheck -PdisablePreDex || { + - ./gradlew connectedCheck || { adb -e logcat -d '*:E'; echo "get the full logcat here:"; (adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true; diff --git a/app/build.gradle b/app/build.gradle index 11e391011..b8a9eff01 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -182,6 +182,9 @@ if (!hasProperty('sourceDeps')) { } } +def isCi = "true".equals(System.getenv("CI")) +def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true")) + android { compileSdkVersion 24 buildToolsVersion '25.0.2' @@ -211,6 +214,13 @@ android { cruncherEnabled = false } + dexOptions { + // Improve build server performance by allowing disabling of pre-dexing + // see http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance + // Skip pre-dexing when running on CI or when disabled via -Dpre-dex=false. + preDexLibraries = preDexEnabled && !isCi + } + defaultConfig { versionCode 1000011 versionName getVersionName() diff --git a/build.gradle b/build.gradle index 749954481..0c5d82fb1 100644 --- a/build.gradle +++ b/build.gradle @@ -8,19 +8,3 @@ buildscript { classpath files('libs/gradle-witness.jar') } } - -/** - * Improve build server performance by allowing disabling of pre-dexing - * (see http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-Build-Server-performance.) - */ -project.ext.preDexLibs = !project.hasProperty('disablePreDex') - -subprojects { - project.plugins.whenPluginAdded { plugin -> - if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) { - project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs - } else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) { - project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs - } - } -}