Member-only story
Why Jetpack Compose Doesn’t Rely on Annotation Processing (And How It Achieves Its Magic)
If you’ve dived into Jetpack Compose for Android development, you’ve probably noticed something curious: composable functions are marked with @Composable
, but Compose doesn't seem to use traditional annotation processing like some other libraries. So, what's going on under the hood?
In this post, we’ll explore why Jetpack Compose avoids annotation processing and how it leverages a compiler plugin instead to make your UI declarative, efficient, and easy to work with.
Let’s unravel the magic!
The Annotation Processing Era
In “classic” Android development, many libraries rely on annotation processing (APT) to generate code at compile time. Think of libraries like Dagger, Room, or ButterKnife. These libraries scan your code for annotations (e.g., @Inject
, @Database
, or @BindView
) and generate the necessary boilerplate code to make everything work.
How Annotation Processing Works
- You add annotations to your code (e.g.,
@Inject
). - During compilation, annotation processors scan your code.
- The processor generates new source files (like Dagger components).