:app:preBuild \--- :app:packageDebug +--- :app:compileDebugJavaWithJavac +--- :app:compressDebugAssets +--- :app:l8DexDesugarLibDebug +--- :app:mergeDebugAssets * +--- :app:mergeDebugJavaResource +--- :app:mergeExtDexDebug +--- :app:mergeLibDexDebug +--- :app:mergeProjectDexDebug +--- :app:preDebugBuild * +--- :app:processDebugManifestForPackage +--- :app:processDebugResources * +--- :app:stripDebugDebugSymbols +--- :app:validateSigningDebug +--- :app:writeDebugAppMetadata \--- :app:writeDebugSigningConfigVersions • Assemble task depends on many tasks • AGP tells Gradle what the inputs and output of the Assemble task When and Where does AGP tell that to Gradle?
manages task dependencies and forms a DAG • Gradle reuses task results based on task input/output • Android Gradle Plugin also has a lifecycle • Recent API changes in AGP are to conform to Gradle's lifecycle • Old Variant API is scheduled to be deprecated in AGP 9.0.0, removed in 10.0.0, so it's recommended to migrate to the new API now
• same input must produce the same output • Performance • appropriate granularity of cache makes high cache hit rate • cache hit is faster than re-execution
of the task implementation class • All declared inputs • Task Identi fi er • Normalized content hash of fi le inputs used as fi ngerprint • build script is also included in key calculations (e.g. `doFirst`, `doLast`) • Env and System Props will not include unless explicitly declared as input
Based on: • GRADLE_USER_HOME • init script • included build scripts • Custom Value Source • System Property and environment • etc… • Requirements: • implements java.io.Serializable
re-use task results based on task input/output • Con fi guration cache • re-use task graph based on con fi guration inputs • Gradle uses different scopes and targets of cache to speed up builds in multiple ways • Con fi guration Cache became the preferred execution mode • Update your API to prevent issues, same as AndroidComponents API
@Output • To enable incremental builds, de fi ne an output property even for tasks that don’t have output • Use Gradle Provider or Property API, instead of Primitive class
a lifecycle • Gradle has different scopes and targets of cache to speed up builds in multiple ways • Make input/output/con fi gurations more deterministic • Use Gradle's provided APIs instead of `project` or `System` • Modify artifacts through AndroidComponents API • Optimize project structure to reduce re-compilation scope and increase parallelism • Use Build Scan and Develocity Plugin
Gradle 8.14.3 : Con fi gurations are initialized lazily • https://docs.gradle.org/8.14.3/ release- notes.html#con fi gurations-are- initialized-lazily • AGP 8.12.0 supports lazy con fi guration • https://issuetracker.google.com/ issues/416349489
Isolated Projects extends the con fi guration cache • the con fi guration model of Gradle projects are "isolated" from each other • Make con fi guration cache more immutable • Make con fi guration cache safely run in parallel