Gradle Basics Interview Questions
BUILD & TOOLING › Gradle
What is Gradle, and what are the main files in an Android project?
What a strong answer covers: Gradle is the build system. settings.gradle.kts lists the modules and repositories; the root build.gradle.kts configures plugins for all modules; each module's build.gradle.kts applies plugins (com.android.application or library, kotlin) and configures android { } (compileSdk, defaultConfig, buildTypes) and dependencies; gradle.properties holds build settings; the wrapper pins the Gradle version.
What is the difference between implementation and api dependencies?
What a strong answer covers: implementation makes a dependency available to the module but not to modules that depend on it, so changes don't trigger recompiling them and the API stays encapsulated. api exposes it transitively, needed when the dependency's types appear in your module's public API. Prefer implementation for faster builds; compileOnly and runtimeOnly also exist.
What are version catalogs, and why use them?
What a strong answer covers: A libs.versions.toml file declares versions, libraries, bundles and plugins in one place; modules reference them as libs.retrofit or alias(libs.plugins.hilt). It keeps versions consistent across modules, gives autocompletion, and makes updates easier, for example with Dependabot or Renovate.
What are the phases of a Gradle build, and why should configuration be cheap?
What a strong answer covers: Initialisation (which projects take part), configuration (evaluate build scripts and build the task graph for every project), and execution (run the requested tasks). Configuration runs on every build, so heavy work at configuration time like network calls or reading files slows every build. Use lazy task APIs (register, Provider), and enable the configuration cache so configuration is reused.
Your build takes 8 minutes. How do you find out why and make it faster?
What a strong answer covers: Measure first: a build scan (--scan) or Build Analyzer shows configuration time, slow tasks and cache misses. Common fixes: turn on the configuration cache and build cache, use KSP instead of kapt, modularise so changes recompile less, avoid api dependencies and dynamic versions, use non-transitive R classes, give the Gradle daemon enough heap, parallel builds, fix tasks that aren't cacheable, use convention plugins instead of allprojects, and a remote cache in CI.