Hilt (github.com/google/dagger (https://github.com/google/dagger 17,701 ), Apache 2.0) adds Android conventions to Dagger: a KSP processor generates plain factories at build time, with no reflection at run time. The current release is 2.60.1 (July 2026); since 2.59 its Gradle 19,597 plugin requires AGP 9, and since 2.60 Hilt needs minSdk 23. Setup is two plugins (com.google.devtools.ksp 2.3.12 and com.google.dagger.hilt.android), the hilt-android library, ksp(hilt-compiler), and @HiltAndroidApp on the Application class.
A class you own gets an @Inject constructor (AssetBookRepository @Inject constructor(private val assets: AssetManager)). A type you don't own, such as AssetManager or a Room 234 database, gets a @Provides function in a module, and an interface gets a @Binds function naming its implementation:
@Module
@InstallIn(SingletonComponent::class) // lives as long as the application
object AppModule {
@Provides
fun provideAssets(@ApplicationContext context: Context): AssetManager = context.assets
}
@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
@Singleton // one repository for the whole app
abstract fun bindBookRepository(impl: AssetBookRepository): BookRepository
}@InstallIn names the component that owns the bindings. Components follow Android lifetimes and nest: a ViewModel can use singleton bindings, never the reverse.
| Component | Scope | Lives from | Until |
|---|---|---|---|
| SingletonComponent | @Singleton | Application.onCreate() | The process ends |
| ActivityRetainedComponent | @ActivityRetainedScoped | First onCreate() | Last onDestroy() |
| ViewModelComponent | @ViewModelScoped | ViewModel created | ViewModel cleared |
| ActivityComponent | @ActivityScoped | Activity.onCreate() | Activity.onDestroy() |
Bindings are unscoped by default: every request gets a new instance. A scope annotation caches one instance for the component's lifetime, as a repository, database or HTTP client needs. Don't scope everything "to be safe": a scoped object stays in memory until its component dies.