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
This commit is contained in:
Hans-Christoph Steiner 2017-10-25 22:15:40 +02:00
parent c3f46bb5fb
commit 5f26a78527
3 changed files with 19 additions and 25 deletions

View File

@ -22,13 +22,13 @@ test:
- ./tools/remove-unused-and-blank-translations.py - ./tools/remove-unused-and-blank-translations.py
- echo "These are unused or blank translations that should be removed:" - echo "These are unused or blank translations that should be removed:"
- git --no-pager diff --exit-code || export EXITVALUE=1 - git --no-pager diff --exit-code || export EXITVALUE=1
- ./gradlew assemble -PdisablePreDex - ./gradlew assemble
# always report on lint errors to the build log # always report on lint errors to the build log
- sed -i -e 's,textReport .*,textReport true,' app/build.gradle - sed -i -e 's,textReport .*,textReport true,' app/build.gradle
- ./gradlew lint -PdisablePreDex - ./gradlew lint
- ./gradlew pmd -PdisablePreDex - ./gradlew pmd
- ./gradlew checkstyle -PdisablePreDex - ./gradlew checkstyle
- ./gradlew test -PdisablePreDex || { - ./gradlew test || {
for log in app/build/reports/*ests/*/*ml; do for log in app/build/reports/*ests/*/*ml; do
echo "read $log here:"; echo "read $log here:";
(cat "$log" | curl --silent -F 'clbin=<-' https://clbin.com) || true; (cat "$log" | curl --silent -F 'clbin=<-' https://clbin.com) || true;
@ -42,12 +42,12 @@ connected10:
variables: variables:
AVD_SDK: "10" AVD_SDK: "10"
script: script:
- ./gradlew assembleDebug -PdisablePreDex - ./gradlew assembleDebug
- emulator64-arm -avd fcl-test-$AVD_SDK -no-skin -no-audio -no-window & - emulator64-arm -avd fcl-test-$AVD_SDK -no-skin -no-audio -no-window &
- ./tools/wait-for-emulator - ./tools/wait-for-emulator
- adb shell input keyevent 82 & - adb shell input keyevent 82 &
- export EXITVALUE=0 - export EXITVALUE=0
- ./gradlew connectedCheck -PdisablePreDex || { - ./gradlew connectedCheck || {
adb -e logcat -d '*:E'; adb -e logcat -d '*:E';
echo "get the full logcat here:"; echo "get the full logcat here:";
(adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true; (adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true;
@ -64,14 +64,14 @@ connected24:
variables: variables:
AVD_SDK: "24" AVD_SDK: "24"
script: script:
- ./gradlew assembleDebug -PdisablePreDex - ./gradlew assembleDebug
- android list avd - android list avd
- emulator64-arm -avd fcl-test-$AVD_SDK -no-audio -no-window & - emulator64-arm -avd fcl-test-$AVD_SDK -no-audio -no-window &
- ./tools/wait-for-emulator - ./tools/wait-for-emulator
- adb shell input keyevent 82 & - adb shell input keyevent 82 &
- adb devices - adb devices
- export EXITVALUE=0 - export EXITVALUE=0
- ./gradlew connectedCheck -PdisablePreDex || { - ./gradlew connectedCheck || {
adb -e logcat -d '*:E'; adb -e logcat -d '*:E';
echo "get the full logcat here:"; echo "get the full logcat here:";
(adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true; (adb -e logcat -d | curl --silent -F 'clbin=<-' https://clbin.com) || true;

View File

@ -182,6 +182,9 @@ if (!hasProperty('sourceDeps')) {
} }
} }
def isCi = "true".equals(System.getenv("CI"))
def preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
android { android {
compileSdkVersion 24 compileSdkVersion 24
buildToolsVersion '25.0.2' buildToolsVersion '25.0.2'
@ -211,6 +214,13 @@ android {
cruncherEnabled = false 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 { defaultConfig {
versionCode 1000011 versionCode 1000011
versionName getVersionName() versionName getVersionName()

View File

@ -8,19 +8,3 @@ buildscript {
classpath files('libs/gradle-witness.jar') 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
}
}
}