Has anyone here used Hilt in a large scale applica...
# android-architecture
m
Has anyone here used Hilt in a large scale application? We have a ton of features in our app, and thus have a lot of modules, and a decently sized object graph. We're currently using anvil, but we're considering moving to hilt since anvil seems a ways off from supporting the k2 compiler, and that's a big negative for us. Hilt seems to keep up to date with kotlin and dagger (which makes sense since it's maintained by google who works closely with jetbrains, where anvil doesn't really seem to have that corporate type backing). All things being equal, i prefer the flexibility of anvil, but the lack of K2 support is big detractor. I'm just concerned about moving all our things that were in contributed subcomponents into the singleton graph. I don't think we're anywhere near the 255 modules it would take to break the jvm limit on constructor parameters, but just more concerned with the overhead. I also don't know how custom hilt components work with things like entry points. Also, for those that do use hilt, do you put your ViewModelFactory instances in the Singleton scope, or in the Activity/Fragment scope?
j
I can't comment on hilt, but internally we are focused on adding k2 support in anvil: https://github.com/square/anvil/blob/main/docs/ROADMAP.md#roadmap.
m
@Jacob Applin Yeah, I've seen the roadmap. It seems reasonable, but as it's a volunteer project mostly, there's no specific timeframe on when the various things will be done. In the meantime, until at least the k2 support is done, we're restricted to kotlin 1.9. So it has me seriously considering migrating to hilt even though i really don't want to. I'd much prefer to stay on anvil.
l
Hi @mattinger, hope you are doing well. 1. We are working in a project just 26 modules and successfully migrated from Dagger to apply Hilt now. I’d say with Hilt, there are more benefits for us, you can read from android official docs. Basically, it’s trade of, I agree that we did not have much modules like your project and we had not same any concerns like you asked.
Also, for those that do use hilt, do you put your ViewModelFactory instances in the Singleton scope, or in the Activity/Fragment scope?
If we work with hilt, we don’t need to think about this because Hilt provides built-in support for injecting
ViewModel
instances. However, if you do have a use case where you need a custom
ViewModelFactory
, the scope depends on how often you want to reuse the factory, nothing change from what you have done.
m
Thanks. Still learning hilt and deciding whether or not i want we should take the leap. It's not a small change migrating from anvil to hilt to say the least.
👍 1
k
I don't think Hilt scales well in large projects, it's very opinionated in terms of instance scoping. We're currently using Dagger + Anvil KSP on a project that has more than 800 modules, so far we're happy with Anvil's flexibility but Dagger compiler becomes a real bottleneck for build performance nowadays, we're researching the possibility to migrate to pure kotlin compiler plugins, either kotlin-inject-anvil or metro (it's still very early stage). If you have all the contributed subcomponents in place, I don't think migrating to hilt will give you any benefits regarding scalability other than K2 support.