Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android - Gradle build optimisation

bkosarzycki
July 26, 2018
110

Android - Gradle build optimisation

Simple tips on how to speed up your Android builds.
This talk is inspired by Stefan Oehme ( Gradle, Lead Developer) talk on “IMPROVING ANDROID BUILD PERFORMANCE” - Droidcon Berlin 2018

bkosarzycki

July 26, 2018
Tweet

Transcript

  1. +

  2. How can we solve this? - Modularization => Compile avoidance

    - Decoupled code => Faster incremental builds
  3. - In 4.8.1 disable Google’s experimental “Configure on demand” *

    What went wrong: A problem occurred evaluating project ':repository'. > Failed to apply plugin [id 'com.android.library'] > Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6. Check gradle version - “instant run” is lost due to Android Studio & gradle incompatibility
  4. Fix for Crashlytics buildTypes { debug { debuggable true minifyEnabled

    false shrinkResources false ext.enableCrashlytics = false ext.alwaysUpdateBuildId = false } }
  5. Predex libraries android { dexOptions { preDexLibraries true } }

    Predexing builds dex file out of libraries so it can be used in incremental builds (not building dex files each time for libraries). Using this feature increases clean build time.
  6. Solution: - Use gradle > 4.7 - Use only Annotation

    Processor which do support incremental builds - Google’s data-binding AP does NOT support it (work in progress) https://github.com/gradle/gradle/issues/5277 Incremental Annotation Processors:
  7. BAZEL builds (Google): $> brew install bazel - different project

    structure - create WORKSPACE file with sdk info - create BUILD file with
  8. - download repository here + docs - compile - make

    an alias for ‘gradle-profiler’ Install gradle profiler: > ./gradlew installDist cp ./build/install/gradle-profiler/* ~/custom/gradle-profiler alias gradle-profiler='~/custom/gradle-profiler/bin/gradle-profiler'
  9. Profile build performance: > ./gradlew clean > gradle-profiler --benchmark --project-dir

    . assembleDebug > open ./profile-out/benchmark.html - from inside project’s directory:
  10. - Linux-only (currently) - Download ‘honest-profiler’ & ‘flame-graph’ Gradle-profiler with

    FlameGraph > gradle-profiler --profile hp --hp-home ~/custom/honest-profiler --fg-home ~/custom/flame-graph --project-dir . assembleDebug
  11. Gradle scans: $ ./gradlew build --scan BUILD SUCCESSFUL in 6s

    Do you accept the Gradle Cloud Services license agreement (https://gradle.com/terms-of-service)? [yes, no] yes Gradle Cloud Services license agreement accepted. Publishing build scan... https://gradle.com/s/czajmbyg73t62 - uses cloud web services
  12. Links / References - Stefan Oehme / Gradle, Lead Developer

    - Droidcon Berlin 2018 - “IMPROVING ANDROID BUILD PERFORMANCE” / Intermediate / Best Practices / Code Quality / Talk - link - Speed-up Android builds - link - TraceView into FlameGraph - link - Gradle-Profiler - link