Migrating Tokopedia Academy App From Dagger Android Into Hilt!
Article Summary
Yehezkiel L from Tokopedia cut their dependency injection boilerplate dramatically by migrating from Dagger Android to Hilt. The result? Cleaner code, faster onboarding, and way less confusion for their team.
Tokopedia's engineering team migrated their Academy Movie App from Dagger Android to Hilt, Google's newer DI library built on top of Dagger. The article walks through their real-world migration experience, showing exactly what changed in their Application class, modules, ViewModels, and injection points.
Key Takeaways
- Eliminated entire ViewModelFactory and Component classes that Dagger required
- Reduced Application class to just @HiltAndroidApp annotation, no boilerplate
- ViewModel injection simplified with @ViewModelInject instead of custom factories
- Dynamic Feature Modules still need manual injection, creating inconsistency
Hilt dramatically reduces Dagger boilerplate and makes dependency injection more approachable, but teams with extensive Dynamic Feature Modules should evaluate the tradeoffs carefully.
About This Article
Yehezkiel L's team found Dagger difficult to work with. The framework required explicit Component, Module, and Inject declarations in every Activity and Fragment, which made it steep to learn.
They switched to Hilt instead. The migration involved adding @HiltAndroidApp to the Application class, @AndroidEntryPoint to view classes, and @InstallIn annotations to modules. Hilt then generated the components automatically.
After the migration, they deleted entire ViewModelFactory and AppComponent classes. The boilerplate code shrank noticeably. They kept Dagger's compile-time correctness and runtime performance.