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

Gradle & Android

Realm
October 06, 2015

Gradle & Android

Presented by Etienne Studer at GOTO Copenhagen 2015

Realm

October 06, 2015
Tweet

More Decks by Realm

Other Decks in Programming

Transcript

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

    • resource/code generation • platform diversity
  2. 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
  3. Product delivery • more than just building APKs • documentation

    with tested code examples • auto-provisioned dev environments • automated release process • …
  4. Android Studio IDE + Android Gradle Plugin + Gradle Platform

    + Android Tooling The Android Build System
  5. Have a single truth of build logic Put all build

    logic into the build.
 Derive all information from the build model.
  6. 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)
  7. • 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
  8. • 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
  9. 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
  10. 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.
  11. 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')
 }
  12. 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!
  13. 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.
  14. 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
  15. 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!
  16. Building with Gradle - experimental The revolutionary new Configuration model

    • From know all things, build some things to know some things, build some things
  17. 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.
  18. Plugin class PicturesPlugin extends RuleSource {
 
 @Model
 void createPicture(Picture

    picture) {}
 
 @Mutate
 void configurePicture(Picture picture) {
 picture.name = 'mypic.jpg'
 picture.tags.addAll(['nature', 'night'])
 }
 
 }
  19. Android (experimental) model {
 android {
 compileSdkVersion = 21
 }


    android.buildTypes {
 debug {
 }
 create(‘qa’)
 }
 }
  20. New Configuration Model • Configuration becomes parallelizable • Managed types

    are externalizable • Model becomes reusable between invocations 
 Revolutionary change!
  21. Performance • Fix hotspots • Cache and reuse • Work

    in parallel • Work in background 1. Build configuration 2. Dependency resolution 3. (Task Execution) Apply To
  22. Dependency Management • dependency management for all the variants of

    the project • variant-aware dependency management for the external dependencies