@HiltAndroidApp: The Entry Point for Hilt DI

@HiltAndroidApp is the main power switch for Hilt dependency injection. You place it on your Application class to trigger code generation and create the top-level dependency container.
Why it exists
Managing dependencies manually in a large Android app is complex and error-prone. Hilt automates this process, and @HiltAndroidApp is the designated starting point. It establishes a single, consistent entry point for Hilt to begin building the dependency graph for the entire application.
The mental model
Think of @HiltAndroidApp as the master switch for your app's entire electrical system (the dependency graph). You place this annotation on your main Application class, and it tells Hilt to power up, scan the project for all Hilt components, and prepare the main dependency container that will be available for the app's entire lifecycle.
How it works
When you add @HiltAndroidApp to a class that extends Application, the Hilt annotation processor runs at compile time. It generates a new base class that your application class will inherit from. This generated code is responsible for creating the application-level dependency container, attaching it to the application's lifecycle, and making it available for injection into other Hilt components.
When to use it
Use this annotation exactly once in your project, on your custom Application class. This is a mandatory first step for any app using Hilt. Every Hilt-enabled app must have a class annotated with @HiltAndroidApp.
When not to use it
Do not use this on any class that is not your main Application subclass. You cannot have multiple classes with this annotation in a single app. Also, do not use it if you are using a different dependency injection framework like Dagger 2 manually or Koin.
One canonical example
First, create a custom Application class and annotate it: @HiltAndroidApp class MyApplication : Application() {}. Second, you must register this class in your AndroidManifest.xml file inside the <application> tag: android:name=".MyApplication". Forgetting this second step is a common error that causes a runtime crash, as the app won't know to use your Hilt-enabled application class.
Interview question
What is the primary function of annotating your Application class with @HiltAndroidApp?
- a.To automatically inject dependencies into all Android framework classes without further configuration.
- b.To define all the dependency modules that Hilt will use throughout the app.
- c.To enable runtime dependency resolution for dynamic feature modules.
- d.To establish the application-level dependency container and initiate Hilt's code generation.Correct
Why? this is the answer
The @HiltAndroidApp annotation serves as the mandatory entry point for Hilt, triggering code generation at compile time and creating the main application-level dependency container. It does not define modules or handle runtime resolution.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles