Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
The Fundamentals  ›  Lesson

Gradle — How the App Gets Built

What is and how to use Gradle? 14 minGradle is the build tool that turns an Android project into an installable app, driven by settings and build files that name the modules, SDK versions and libraries.

Gradle — How the App Gets Built

You press Run and, a few seconds later, Sprout appears on the emulator. Between those two moments, a tool compiled your code, packed your images, downloaded libraries and signed the result. That tool is Gradle, and you steer it with a few short files.

The rule

Settings names the modules; each module's build file says how to build it.

An Android project has a small set of Gradle files:

  • settings.gradle.kts — lists the modules in the project, like include(":app"), and where to download libraries from.
  • build.gradle.kts in the project root — shared plugin setup.
  • app/build.gradle.kts — the important one: how to build the app module.
  • gradle/libs.versions.toml — the version catalog, one place for library versions.
android {
    namespace = "com.example.sprout"
    compileSdk = 35
    defaultConfig {
        applicationId = "com.example.sprout"
        minSdk = 26          // oldest Android version allowed
        targetSdk = 35       // version the app is designed for
        versionCode = 3      // internal number, must go up each release
        versionName = "1.2"  // what users see
    }
}
dependencies {
    implementation(libs.androidx.activity.compose)
}

applicationId is the app's unique identity on a device and in the store. implementation(...) adds a library your code can use.

The shortcut

For any build question, ask "which file owns this?" Project-wide list → settings. Anything about one app → its module file.

Adding an image-loading library to SproutStep 1 of 4
  1. Pick the owner

    Only the app module uses it → app/build.gradle.kts.

You can also build from a terminal with the Gradle wrapper, which downloads the right Gradle version for you:

./gradlew assembleDebug

A classic mistake is editing a build file and forgetting to sync: the code then cannot "see" the new library.

Drills

Answer fast — trust the rule.

quick drill

Which file lists the modules that make up the project?

quick drill

Sprout sets minSdk = 26. What does that control?

quick drill

Which value must increase every time you publish a new release?

quick drill

What does ./gradlew assembleDebug do?

Remember

  • Settings names the modules; each module's build file says how to build it.
  • Ask "which file owns this?" before editing.
  • After changing a build file, sync.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRead Sprout's build file

Sprout's module build file has minSdk = 26, targetSdk = 35 and implementation(libs.androidx.navigation.compose). Explain in plain words what each of these three lines means and what you must do after editing the file.