Gradle & Android

1fa9cb8c7997c8c4d3d251fb5e41f749?s=47 Realm
October 06, 2015

Gradle & Android

Presented by Etienne Studer at GOTO Copenhagen 2015

1fa9cb8c7997c8c4d3d251fb5e41f749?s=128

Realm

October 06, 2015
Tweet

Transcript

  1. 2.
  2. 4.

    Facts • implicit complexity of the domain • multi-language support

    • resource/code generation • platform diversity
  3. 6.

    android { compileSdkVersion 20 buildToolsVersion "20.0.0" flavorDimensions "version", "abi" productFlavors

    { free { flavorDimension "version" } paid { flavorDimension "version" } arm { flavorDimension "abi" } x86 { flavorDimension "abi" } } Conciseness compileX86FreeDebugAidl compileX86FreeDebugRenderscript compileX86FreeTest compileX86FreeTestAidl compileX86FreeTestRenderscript dexX86FreeTest generateX86FreeDebugBuildConfig generateX86FreeTestBuildConfig mergeX86FreeDebugAssets mergeX86FreeDebugResources mergeX86FreeTestAssets mergeX86FreeTestResources packageX86FreeTest prepareX86FreeDebugDependencies prepareX86FreeTestDependencies processX86FreeDebugManifest processX86FreeDebugResources processX86FreeTestJavaRes processX86FreeTestResources processX86FreeTestTestManifest validateDebugSigning assembleX86Paid - Assembles all builds for flavor X86Paid [assembleX86PaidDebug, assembleX86PaidRelease] assembleX86PaidDebug - Assembles the Debug build for flavor X86Paid compileX86PaidDebug compileX86PaidDebugAidl compileX86PaidDebugRenderscript dexX86PaidDebug generateX86PaidDebugBuildConfig mergeX86PaidDebugAssets mergeX86PaidDebugResources packageX86PaidDebug prepareX86PaidDebugDependencies processX86PaidDebugJavaRes processX86PaidDebugManifest processX86PaidDebugResources validateDebugSigning assembleX86PaidRelease - Assembles the Release build for flavor X86Paid compileX86PaidRelease compileX86PaidReleaseAidl compileX86PaidReleaseRenderscript dexX86PaidRelease generateX86PaidReleaseBuildConfig mergeX86PaidReleaseAssets mergeX86PaidReleaseResources packageX86PaidRelease prepareX86PaidReleaseDependencies processX86PaidReleaseJavaRes processX86PaidReleaseManifest processX86PaidReleaseResources assembleX86PaidTest - Assembles the Test build for the X86PaidDebug build compileX86PaidDebug compileX86PaidDebugAidl compileX86PaidDebugRenderscript compileX86PaidTest compileX86PaidTestAidl compileX86PaidTestRenderscript dexX86PaidTest generateX86PaidDebugBuildConfig generateX86PaidTestBuildConfig mergeX86PaidDebugAssets mergeX86PaidDebugResources mergeX86PaidTestAssets mergeX86PaidTestResources packageX86PaidTest prepareX86PaidDebugDependencies prepareX86PaidTestDependencies processX86PaidDebugManifest processX86PaidDebugResources processX86PaidTestJavaRes processX86PaidTestResources processX86PaidTestTestManifest validateDebugSigning build - Assembles and tests this project. [assemble, check] buildDependents - Assembles and tests this project and all projects that depend on it. [build] buildNeeded - Assembles and tests this project and all projects it depends on. [build] clean - Deletes the build directory. Help tasks ---------- dependencies - Displays all dependencies declared in root project 'flavors'. dependencyInsight - Displays the insight into a specific dependency in root project 'flavors'. help - Displays a help message projects - Displays the sub-projects of root project 'flavors'. properties - Displays the properties of root project 'flavors'. tasks - Displays the tasks runnable from root project 'flavors' (some of the displayed tasks may belong to subprojects). Install tasks ------------- installArmFreeDebug - Installs the Debug build for flavor ArmFree compileArmFreeDebug compileArmFreeDebugAidl compileArmFreeDebugRenderscript dexArmFreeDebug generateArmFreeDebugBuildConfig mergeArmFreeDebugAssets mergeArmFreeDebugResources packageArmFreeDebug prepareArmFreeDebugDependencies processArmFreeDebugJavaRes processArmFreeDebugManifest processArmFreeDebugResources validateDebugSigning installArmFreeTest - Installs the Test build for the ArmFreeDebug build compileArmFreeDebug compileArmFreeDebugAidl compileArmFreeDebugRenderscript compileArmFreeTest compileArmFreeTestAidl compileArmFreeTestRenderscript dexArmFreeTest generateArmFreeDebugBuildConfig generateArmFreeTestBuildConfig mergeArmFreeDebugAssets mergeArmFreeDebugResources mergeArmFreeTestAssets mergeArmFreeTestResources packageArmFreeTest prepareArmFreeDebugDependencies prepareArmFreeTestDependencies processArmFreeDebugManifest processArmFreeDebugResources processArmFreeTestJavaRes processArmFreeTestResources processArmFreeTestTestManifest validateDebugSigning installArmPaidDebug - Installs the Debug build for flavor ArmPaid compileArmPaidDebug compileArmPaidDebugAidl compileArmPaidDebugRenderscript dexArmPaidDebug generateArmPaidDebugBuildConfig mergeArmPaidDebugAssets mergeArmPaidDebugResources packageArmPaidDebug prepareArmPaidDebugDependencies processArmPaidDebugJavaRes processArmPaidDebugManifest processArmPaidDebugResources validateDebugSigning installArmPaidTest - Installs the Test build for the ArmPaidDebug build compileArmPaidDebug compileArmPaidDebugAidl compileArmPaidDebugRenderscript compileArmPaidTest compileArmPaidTestAidl compileArmPaidTestRenderscript dexArmPaidTest generateArmPaidDebugBuildConfig generateArmPaidTestBuildConfig mergeArmPaidDebugAssets mergeArmPaidDebugResources mergeArmPaidTestAssets mergeArmPaidTestResources packageArmPaidTest prepareArmPaidDebugDependencies prepareArmPaidTestDependencies processArmPaidDebugManifest processArmPaidDebugResources processArmPaidTestJavaRes processArmPaidTestResources processArmPaidTestTestManifest validateDebugSigning installX86FreeDebug - Installs the Debug build for flavor X86Free compileX86FreeDebug compileX86FreeDebugAidl compileX86FreeDebugRenderscript dexX86FreeDebug generateX86FreeDebugBuildConfig mergeX86FreeDebugAssets mergeX86FreeDebugResources packageX86FreeDebug prepareX86FreeDebugDependencies processX86FreeDebugJavaRes processX86FreeDebugManifest processX86FreeDebugResources validateDebugSigning installX86FreeTest - Installs the Test build for the X86FreeDebug build compileX86FreeDebug compileX86FreeDebugAidl compileX86FreeDebugRenderscript compileX86FreeTest compileX86FreeTestAidl compileX86FreeTestRenderscript dexX86FreeTest generateX86FreeDebugBuildConfig generateX86FreeTestBuildConfig mergeX86FreeDebugAssets mergeX86FreeDebugResources mergeX86FreeTestAssets mergeX86FreeTestResources packageX86FreeTest prepareX86FreeDebugDependencies prepareX86FreeTestDependencies processX86FreeDebugManifest processX86FreeDebugResources processX86FreeTestJavaRes processX86FreeTestResources processX86FreeTestTestManifest validateDebugSigning installX86PaidDebug - Installs the Debug build for flavor X86Paid compileX86PaidDebug compileX86PaidDebugAidl
  4. 8.

    Product delivery • more than just building APKs • documentation

    with tested code examples • auto-provisioned dev environments • automated release process • …
  5. 9.
  6. 10.

    Android Studio IDE + Android Gradle Plugin + Gradle Platform

    + Android Tooling The Android Build System
  7. 11.

    Have a single truth of build logic Put all build

    logic into the build.
 Derive all information from the build model.
  8. 12.

    In a unified build,
 Gradle is the single source of

    build logic. Gradle Launcher AS Tooling API Server (daemon) Cmd Line (developer) (build master) (cont integ)
  9. 13.

    • Proxy for embedding Gradle • Extension mechanism to provide

    custom models • See DefaultAndroidProject model Client VM with gradle-tooling-api.jar Gradle Daemon for Gradle build get build models invoke build tasks Tooling API
  10. 14.

    • Backward & forward compatible
 From 1.0 to 2.8 •

    Runtime Isolation
 Separate daemon process • High Level Services
 Build Cancellation,Continuous Mode, Test Execution, etc. • Build Event Model
 Life-cycle events, task events, test events Tooling API
  11. 17.

    Typically, not much changes in the build between consecutive invocations

    of the build. When little changes in the build, little work should be done by the build. Observation
  12. 20.

    Execution Phase • Incremental build feature .Only run a task

    if its input or output has changed since the
 previous run Inputs —> Task —> Outputs Define inputs and outputs on your custom tasks.
  13. 21.

    Execution Phase class ConversionTask extends DefaultTask { @InputFiles
 def sourceFiles


    
 @OutputDirectory
 def targetDirectory
 
 @TaskAction
 def doSomeWork() {
 // consume the sourceFiles and write the result
 // to a file in the targetDirectory
 } } task foo(type: MyTask) { 
 sourceFiles = files('input.txt'); 
 targetDirectory = file('build/result')
 }
  14. 23.

    Execution Phase • Faster incremental builds
 .Improvements to the management

    of File checksums
 .Most notable for almost uptodate builds • Faster compilation for continuous builds
 .Compiler daemon is kept alive for the entire ContB session 
 
 Evolutionary improvements with each release!
  15. 24.

    Configuration Phase • Imperative build logic (input)
 .Even when providing

    a declarative DSL
 .Lazy evaluation tricks
 .Lazy collection tricks
 .Project#afterEvaluate tricks • Declarative build model (output) Know all things, build some things.
  16. 25.

    Configuration Phase • Android
 .Full model construction at evaluation time


    .Full dependency resolution/processing at evaluation
 .Hard to know when things are ready, e.g flavors
 .Even when calling gradlew tasks
  17. 26.

    Configuration Phase • Faster build script compilation
 .Caching the compiled

    form of the build scripts
 .Newer version of Groovy used for the DSL parsing • Configure on demand
 .Attempt to only configure the projects relevant to the
 requested tasks 
 Evolutionary improvements with each release!
  18. 31.

    Building with Gradle - experimental The revolutionary new Configuration model

    • From know all things, build some things to know some things, build some things
  19. 32.

    New Configuration Model Apply the concepts already available in the

    Execution phase to the Configuration phase. Describe what the model should look like and Gradle will provide the implementation.
  20. 35.

    Plugin class PicturesPlugin extends RuleSource {
 
 @Model
 void createPicture(Picture

    picture) {}
 
 @Mutate
 void configurePicture(Picture picture) {
 picture.name = 'mypic.jpg'
 picture.tags.addAll(['nature', 'night'])
 }
 
 }
  21. 37.
  22. 38.

    Android (experimental) model {
 android {
 compileSdkVersion = 21
 }


    android.buildTypes {
 debug {
 }
 create(‘qa’)
 }
 }
  23. 39.

    New Configuration Model • Configuration becomes parallelizable • Managed types

    are externalizable • Model becomes reusable between invocations 
 Revolutionary change!
  24. 41.

    Performance • Fix hotspots • Cache and reuse • Work

    in parallel • Work in background 1. Build configuration 2. Dependency resolution 3. (Task Execution) Apply To
  25. 43.

    Dependency Management • dependency management for all the variants of

    the project • variant-aware dependency management for the external dependencies
  26. 45.