Gradle & Android Etienne Studer, VP of Product Tooling - - PowerPoint PPT Presentation

gradle android
SMART_READER_LITE
LIVE PREVIEW

Gradle & Android Etienne Studer, VP of Product Tooling - - PowerPoint PPT Presentation

Gradle & Android Etienne Studer, VP of Product Tooling Motivation Facts implicit complexity of the domain multi-language support resource/code generation platform diversity Complexity compileX86FreeDebug


slide-1
SLIDE 1

Gradle & Android

Etienne Studer,
 VP of Product Tooling

slide-2
SLIDE 2
slide-3
SLIDE 3

Motivation

slide-4
SLIDE 4

Facts

  • implicit complexity of the domain
  • multi-language support
  • resource/code generation
  • platform diversity
slide-5
SLIDE 5

Complexity

slide-6
SLIDE 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

compileX86FreeDebug 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 compileX86PaidDebugRenderscript
slide-7
SLIDE 7

Polyglot

  • multiple languages
  • multiple teams
  • coordinated releases
slide-8
SLIDE 8

Product delivery

  • more than just building APKs
  • documentation with tested code examples
  • auto-provisioned dev environments
  • automated release process
slide-9
SLIDE 9
slide-10
SLIDE 10

Android Studio IDE + Android Gradle Plugin + Gradle Platform + Android Tooling

The Android Build System

slide-11
SLIDE 11

Have a single truth of build logic

Put all build logic into the build.
 Derive all information from the build model.

slide-12
SLIDE 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)

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 15

Performance

slide-16
SLIDE 16

Minimize the build time while 
 using as little memory as needed.

Goal

slide-17
SLIDE 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

slide-18
SLIDE 18

Performance enhancements are achieved through evolutionary improvements and revolutionary changes.

Approach

slide-19
SLIDE 19

Building with Gradle - today

2-phase build:

  • Configuration phase
  • Execution phase
slide-20
SLIDE 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.

slide-21
SLIDE 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')
 }

slide-22
SLIDE 22

Execution Phase

  • Continuous build feature

.Keep the session running between build runs

gradlew test -t

slide-23
SLIDE 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!

slide-24
SLIDE 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.

slide-25
SLIDE 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

slide-26
SLIDE 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!

slide-27
SLIDE 27

Android Build - Pre-dexing

slide-28
SLIDE 28
  • Clean Safe Cache
  • Parallelization
  • Distributed Cache

Pre-Dexing Optimizations

slide-29
SLIDE 29

Android Build - Dexing

slide-30
SLIDE 30
  • Faster Dexing
  • Incremental Dexing

Dexing Optimizations

slide-31
SLIDE 31

Building with Gradle - experimental

The revolutionary new Configuration model

  • From know all things, build some things to

know some things, build some things

slide-32
SLIDE 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.

slide-33
SLIDE 33
  • Richer modeling
  • Cleaner modeling
  • Collaborative modeling
  • Comprehensible model


Modeling

slide-34
SLIDE 34

Managed types

@Managed interface Picture { String getName() void setName(String name) List<String> getTags() }

slide-35
SLIDE 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'])
 }
 
 }

slide-36
SLIDE 36

DSL

model {
 picture(Picture) {
 name = 'mypic.jpg'
 tags.addAll(['night', 'moon'])
 }
 }

slide-37
SLIDE 37

Report

slide-38
SLIDE 38

Android (experimental)

model {
 android {
 compileSdkVersion = 21
 }
 android.buildTypes {
 debug {
 }
 create(‘qa’)
 }
 }

slide-39
SLIDE 39

New Configuration Model

  • Configuration becomes parallelizable
  • Managed types are externalizable
  • Model becomes reusable between invocations

Revolutionary change!

slide-40
SLIDE 40

Roadmap 6-12 months

  • Radically improve performance
  • Gentrify dependency management

No guarantees or commitments.

slide-41
SLIDE 41

Performance

  • Fix hotspots
  • Cache and reuse
  • Work in parallel
  • Work in background
  • 1. Build configuration
  • 2. Dependency resolution
  • 3. (Task Execution)

Apply To

slide-42
SLIDE 42

Performance

slide-43
SLIDE 43

Dependency Management

  • dependency management for all the variants of

the project

  • variant-aware dependency management for the

external dependencies

slide-44
SLIDE 44

Gradle.com

slide-45
SLIDE 45

MOOC

slide-46
SLIDE 46

Gradle is hiring

http://gradle.org/gradle-jobs

slide-47
SLIDE 47

Gradle & Android

Etienne Studer,
 VP of Product Tooling