tezvyn:

What is the difference between project-level and module-level build.gradle?

Curated by the Tezvyn teamSource: developer.android.combeginner
What is the difference between project-level and module-level build.gradle?
WHAT IT TESTS

Gradle scope in multi-module Android projects.

ANSWER OUTLINE

Project level sets plugin repos and shared versions; module level sets dependencies, build types, and flavors.

RED FLAG

Claiming both files do the same thing or misplacing plugins.

WHAT THIS TESTS: This question checks whether you understand the hierarchical nature of Gradle builds in Android and can distinguish between global project configuration and local module configuration. A senior candidate should demonstrate awareness of separation of concerns, know where to apply plugins, and understand that modern Android projects are almost always multi-module. The interviewer wants to see that you have debugged build issues by knowing which file to edit.

A GOOD ANSWER COVERS: A strong answer explains that the project-level build.gradle acts as the global configuration for the entire Gradle build. It typically lives in the root project directory and defines plugin repositories in the plugins block or dependency resolution management, sets up shared version catalogs, and may declare classpath dependencies for Gradle plugins themselves. In contrast, the module-level build.gradle lives inside each module folder such as app or library modules and applies the Android-specific plugins like com.android.application or com.android.library. It declares the module's own dependencies, configures the android block with compileSdk, defaultConfig containing applicationId and minSdk, and defines build types like debug and release, product flavors, signing configurations, and packaging options. A great candidate also notes that a single project has exactly one project-level file but can have many module-level files, and that the module file can reference ext variables or version catalogs defined at the project level.

COMMON WRONG ANSWERS: Red flags include saying both files are identical in purpose, claiming that dependencies always go in the project-level file, or stating that the Android application plugin belongs in the project-level build.gradle. Another weak signal is describing only the app module and forgetting that library modules also have their own module-level build.gradle files. Confusing the old classpath dependencies in buildscript blocks with modern plugins DSL also suggests outdated knowledge.

LIKELY FOLLOW-UPS: An interviewer may ask where you should define a dependency version that multiple modules share, how version catalogs change this workflow, or what happens when you apply a plugin at the project level versus the module level. They might also ask how buildSrc or convention plugins reduce duplication across many module-level files, or how to configure a custom Gradle plugin in the project-level file.

ONE CONCRETE EXAMPLE: Imagine a project with an app module and two library modules. The project-level build.gradle sets pluginManagement repositories to google() and mavenCentral(), and defines an ext.kotlin_version variable. Each module-level build.gradle applies plugins such as com.android.application for the app and com.android.library for the libraries, sets compileSdk to 34, and adds unique dependencies like Retrofit for the app module and JUnit for a library test suite. The app module also defines buildTypes with minification enabled in release, while the library modules do not.

Source: developer.android.com

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

What is the difference between project-level and module-level build.gradle? · Tezvyn