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 compileX86FreeDebugAidl compileX86FreeDebugRenderscript compileX86FreeTest compileX86FreeTestAidl compileX86FreeTestRenderscript dexX86FreeTest generateX86FreeDebugBuildConfig generateX86FreeTestBuildConfig mergeX86FreeDebugAssets mergeX86FreeDebugResources mergeX86FreeTestAssets mergeX86FreeTestResources packageX86FreeTest prepareX86FreeDebugDependencies prepareX86FreeTestDependencies processX86FreeDebugManifest processX86FreeDebugResources processX86FreeTestJavaRes processX86FreeTestResources Conciseness 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 android { processX86PaidReleaseJavaRes processX86PaidReleaseManifest processX86PaidReleaseResources assembleX86PaidTest - Assembles the Test build for the X86PaidDebug build compileX86PaidDebug compileX86PaidDebugAidl compileSdkVersion 20 compileX86PaidDebugRenderscript compileX86PaidTest compileX86PaidTestAidl compileX86PaidTestRenderscript dexX86PaidTest generateX86PaidDebugBuildConfig generateX86PaidTestBuildConfig buildToolsVersion "20.0.0" mergeX86PaidDebugAssets mergeX86PaidDebugResources mergeX86PaidTestAssets mergeX86PaidTestResources packageX86PaidTest prepareX86PaidDebugDependencies prepareX86PaidTestDependencies processX86PaidDebugManifest processX86PaidDebugResources processX86PaidTestJavaRes processX86PaidTestResources processX86PaidTestTestManifest validateDebugSigning flavorDimensions "version" , "abi" 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). productFlavors { Install tasks ------------- installArmFreeDebug - Installs the Debug build for flavor ArmFree compileArmFreeDebug compileArmFreeDebugAidl free { compileArmFreeDebugRenderscript dexArmFreeDebug generateArmFreeDebugBuildConfig mergeArmFreeDebugAssets mergeArmFreeDebugResources packageArmFreeDebug prepareArmFreeDebugDependencies flavorDimension "version" processArmFreeDebugJavaRes processArmFreeDebugManifest processArmFreeDebugResources validateDebugSigning installArmFreeTest - Installs the Test build for the ArmFreeDebug build compileArmFreeDebug } compileArmFreeDebugAidl compileArmFreeDebugRenderscript compileArmFreeTest compileArmFreeTestAidl compileArmFreeTestRenderscript dexArmFreeTest generateArmFreeDebugBuildConfig paid { generateArmFreeTestBuildConfig mergeArmFreeDebugAssets mergeArmFreeDebugResources mergeArmFreeTestAssets mergeArmFreeTestResources packageArmFreeTest flavorDimension "version" 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 arm { processArmPaidDebugResources validateDebugSigning installArmPaidTest - Installs the Test build for the ArmPaidDebug build compileArmPaidDebug compileArmPaidDebugAidl compileArmPaidDebugRenderscript flavorDimension "abi" compileArmPaidTest compileArmPaidTestAidl compileArmPaidTestRenderscript dexArmPaidTest generateArmPaidDebugBuildConfig generateArmPaidTestBuildConfig mergeArmPaidDebugAssets } mergeArmPaidDebugResources mergeArmPaidTestAssets mergeArmPaidTestResources packageArmPaidTest prepareArmPaidDebugDependencies prepareArmPaidTestDependencies x86 { processArmPaidDebugManifest processArmPaidDebugResources processArmPaidTestJavaRes processArmPaidTestResources processArmPaidTestTestManifest validateDebugSigning installX86FreeDebug - Installs the Debug build for flavor X86Free flavorDimension "abi" 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
Polyglot • multiple languages • multiple teams • coordinated releases
Product delivery • more than just building APKs • documentation with tested code examples • auto-provisioned dev environments • automated release process • …
The Android Build System Android Studio IDE + Android Gradle Plugin + Gradle Platform + Android Tooling
Have a single truth of build logic Put all build logic into the build. Derive all information from the build model.
AS Cmd Line (developer) (build master) Tooling API Launcher Gradle Server (daemon) (cont integ) In a unified build, Gradle is the single source of build logic.
Tooling API • Proxy for embedding Gradle • Extension mechanism to provide custom models • See DefaultAndroidProject model get build models Client VM Gradle Daemon with gradle-tooling-api.jar for Gradle build invoke build tasks
Tooling API • 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
Performance
Goal Minimize the build time while using as little memory as needed.
Observation 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.
Approach Performance enhancements are achieved through evolutionary improvements and revolutionary changes.
Building with Gradle - today 2-phase build: - Configuration phase - Execution phase
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.
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') }
Execution Phase • Continuous build feature .Keep the session running between build runs gradlew test -t
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!
Recommend
More recommend