Android Studio: Ctrl + F9 vs. Clean & Rebuild Project
If you have spent any time developing Android apps in Kotlin or Java, you have likely run into this frustrating scenario: you paste new image assets into res/drawable/ or add new view IDs in XML, but Android Studio keeps highlighting them in red with "Unresolved reference".
Understanding how Gradle builds your project—and knowing when to use Ctrl + F9 versus a full Clean & Rebuild—will save you hours of debugging phantom build errors.
1. Ctrl + F9 (Make Project)
Pressing Ctrl + F9 (or Cmd + F9 on macOS) performs an incremental build. Gradle checks what changed since the last build and compiles only those specific files.
- Editing Kotlin or Java logic inside existing classes.
- Adjusting layout properties like
padding,margin, ortextColor. - Updating text content in existing
strings.xmlentries. - Quickly testing code edits during active development.
2. Clean & Rebuild Project
A Clean Project operation deletes the entire build/ directory, wiping all previously generated class files and the auto-generated R.java resource index. The subsequent Rebuild forces AAPT2 (Android Asset Packaging Tool) to re-index all resources from scratch.
- Adding new image drawables (
.png,.jpg,.webp) tores/drawable/. - Defining new
@+id/attributes in XML layouts. - Adding new libraries or plugins to
build.gradle. - Fixing "phantom" red editor errors when the app compiles and runs fine.
Comparison Table
| Scenario | Recommended Action | Why? |
|---|---|---|
| Modifying Kotlin functions | Ctrl + F9 | Fast incremental compilation of changed source code. |
| Pasting new PNG assets | Clean & Rebuild | Forces AAPT2 to index new raw assets into R.drawable. |
Adding new @+id tags |
Clean & Rebuild | Regenerates R.id so the editor recognizes the new view IDs. |
| False red errors in IDE | Clean & Rebuild | Resets stale IDE caches and syncs editor state with compiler output. |
Comments
Post a Comment