Project Structure & Gradle Sync

Android Studio: The IDE Itself

Chapter 2 · Project Structure & Gradle Sync

Chapter 1 placed project structure and Gradle sync squarely on the Android-specific side of the IDE — nothing here exists in a plain IntelliJ IDEA install with no Android support. This chapter covers both directly: how an Android Studio project is actually organized, and what that "Gradle Sync" progress bar is really doing.

Android Studio's Project Structure

An Android Studio project is not one flat folder of files — it's organized into modules, most commonly at least one app module (the application itself) and optionally additional library modules. Inside the app module, source code lives under app/src/main/java and resources (layouts, strings, images) under app/src/main/res. This module-based layout, and the project/module distinction it creates, is fundamentally different from a simpler text editor's own flat "just a folder of files" view.

What Gradle Actually Is

Gradle itself is a general-purpose build automation tool, used well beyond Android — it isn't something Google invented. Android's own build process is layered on top of plain Gradle via the Android Gradle Plugin (AGP), which adds Android-specific build steps (packaging an APK, handling resources, managing the Android SDK) to Gradle's own general build-automation engine.

build.gradle Files: Two Different Scopes

// Project-level: build.gradle (Project: MyApp) plugins { id 'com.android.application' version '8.1.0' apply false } // Module-level: app/build.gradle android { compileSdk 34 } dependencies { implementation 'androidx.core:core-ktx:1.12.0' }

A common early point of confusion: there isn't just one build.gradle file. The project-level file (alongside settings.gradle) configures overall build settings and lists which modules belong to the project. The module-level file — app/build.gradle — is where SDK versions, the application ID, and individual library dependencies actually live. Adding a new library dependency almost always means editing the module-level file, not the project-level one.

What "Gradle Sync" Is Actually Doing

Clicking Sync Now (or first opening a project) isn't just Android Studio reloading files from disk. It actually runs Gradle itself: resolving every declared dependency, downloading any new libraries that aren't already cached locally, and regenerating the IDE's own internal understanding of the project's module and dependency graph — the information code completion, error-checking, and navigation all depend on being accurate. This is a real process that touches the network and disk, which is why it can genuinely take real time, especially after adding a new dependency for the first time — not an instant IDE refresh.

When You Need to Sync Manually

Editing build.gradle — adding a dependency, changing an SDK version — has no effect on the actual project until a sync happens. Android Studio usually detects the change and shows a "Sync Now" banner automatically, but that banner can be missed or accidentally dismissed; knowing the toolbar's own Sync button exists (rather than assuming something is broken) avoids real confusion when code that should now be available still shows as unresolved.

FileScopeControls
Project-level build.gradleWhole projectPlugin versions, overall build settings
settings.gradleWhole projectWhich modules belong to the project
Module-level app/build.gradleOne module (app)SDK versions, application ID, dependencies
Yes, commit build.gradle to version control
Unlike some IDE-specific configuration files, build.gradle files genuinely define the actual build — they belong in version control (Git & GitHub Foundations' own material) alongside the rest of the project's source, not excluded via .gitignore the way IDE-generated cache/workspace files typically are.
Unresolved code often means "sync," not "something's broken"
It's easy to assume that code failing to complete or resolve correctly means the IDE itself is malfunctioning. Very often, the real cause is simply that a Gradle Sync hasn't happened yet — after pulling in changes that added a new dependency, or after manually editing build.gradle without noticing the sync banner. The fix in that situation is almost always Sync Now, not restarting the IDE or reinstalling anything.

Hands-On Exercises

Exercise 1

A developer wants to add a new library dependency to their app. Which build.gradle file should they edit — the project-level one or the module-level one — and why?

📄 View solution
Exercise 2

After pulling new commits from a teammate that added a dependency to app/build.gradle, a developer sees the newly-added library's classes showing as "cannot resolve symbol" in their editor. Using this chapter's own material, explain the likely cause and the fix — without assuming the IDE itself is broken.

📄 View solution
Exercise 3

Explain, in your own words, why Gradle Sync can genuinely take real time to complete (sometimes noticeably so), rather than being an instant operation the way simply opening a file is.

📄 View solution

Chapter 2 Quick Reference

  • An Android Studio project is organized into modules (e.g. app), not one flat folder
  • Gradle is a general build tool; the Android Gradle Plugin (AGP) adds Android-specific build steps on top of it
  • Project-level build.gradle/settings.gradle vs. module-level app/build.gradle — dependencies almost always go in the module-level file
  • Gradle Sync genuinely resolves dependencies and rebuilds the IDE's own project understanding — a real process, not an instant refresh
  • "Cannot resolve symbol" after a build.gradle change is almost always a missed sync, not a broken IDE