Hilt (Dependency Injection)
Android's recommended dependency injection library, built on top of Dagger 2. Hilt simplifies Dagger setup for Android by providing standard components for Activity, Fragment, ViewModel, Service, and WorkManager. Eliminates the boilerplate of manual Dagger component creation while retaining compile-time DI code generation. The Google-endorsed replacement for manual DI or Service Locator patterns in Android.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
DI framework — no direct security surface. Enables secure patterns (injecting auth credentials vs hardcoding). Google maintains. No network calls.
⚡ Reliability
Best When
You're building a multi-module Android app with complex dependency graphs and want compile-time DI safety, lifecycle-aware scoping, and Google Jetpack integration.
Avoid When
You want simple, pragmatic DI without code generation overhead — Koin's runtime DI is easier to set up and debug for teams new to dependency injection.
Use Cases
- • Inject agent dependencies (repositories, network clients, databases) into Android ViewModels and Fragments without manual factory boilerplate
- • Scope agent services and singletons to appropriate Android component lifecycles (Application, Activity, ViewModel) using Hilt's built-in scopes
- • Inject mock dependencies in Android instrumented tests using @TestInstallIn and HiltAndroidTest for agent integration testing
- • Provide different agent implementations based on build variants (debug/release, local/remote) using Hilt modules with @InstallIn
- • Wire WorkManager workers with Hilt dependencies using HiltWorker for background agent task execution
Not For
- • Non-Android JVM applications — Hilt is Android-specific; use Dagger 2, Koin, or Spring DI for server-side Kotlin/Java
- • Simple Android apps with few dependencies — Hilt's compile-time code generation adds build time overhead not worth it for small projects
- • Teams new to DI concepts — Hilt's annotations and component hierarchy have a learning curve; Koin's runtime DI is simpler to learn
Interface
Authentication
DI framework — no authentication concepts. Auth credentials are injected as dependencies.
Pricing
Google open source project. Apache 2.0 license.
Agent Metadata
Known Gotchas
- ⚠ Hilt code generation errors appear at Gradle build time with references to generated Dagger components — trace errors back to the @Module or @Provides that caused the type mismatch
- ⚠ Hilt and Jetpack Compose require specific integration — @HiltViewModel is required for Compose + Hilt ViewModel injection; using viewModel() without it causes IllegalStateException
- ⚠ Multi-module Hilt requires each module to apply the Hilt Gradle plugin — missing the plugin in a library module causes 'Unresolved reference: HiltAndroidApp' errors
- ⚠ Hilt's @InstallIn scope hierarchy is fixed — you cannot inject ActivityScoped dependencies into SingletonScoped components; dependency scope must match or be wider than component scope
- ⚠ Testing with Hilt requires replacing Hilt test runner in build.gradle AND @HiltAndroidTest annotation — partial setup causes test DI graph to be incomplete
- ⚠ Hilt adds significant build time overhead via kapt/KSP code generation — for large projects, incremental KSP (not kapt) is important for acceptable build times
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for Hilt (Dependency Injection).
Scores are editorial opinions as of 2026-03-06.