Tokopedia Aug 14, 2020

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

Critical Insight

Hilt dramatically reduces Dagger boilerplate and makes dependency injection more approachable, but teams with extensive Dynamic Feature Modules should evaluate the tradeoffs carefully.

The team identified one major gotcha that could block adoption for apps with complex modularization strategies.

About This Article

Problem

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.

Solution

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.

Impact

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.