Closed yamasa closed 4 years ago
From https://dagger.dev/api/2.28/dagger/hilt/android/HiltAndroidApp.html
Annotation for marking the Application class where the Dagger components should be generated. Since all components will be built in the same compilation as the annotated application, all modules and entry points that should be installed in the component need to be transitive compilation dependencies of the annotated application.
Given that dynamic feature modules aren't dependencies of the application, seems like it's a no-go, at least for now.
Just FYI, we're going to come back to this issue about Hilt after the official launch. Thanks for filing it though and sorry for the wait!
Thank you. I'm really looking forward to it!
@yamasa can you try this? https://github.com/google/dagger/issues/970#issuecomment-565317632
I am not using it with dynamic features yet. But I am not implementing my data module in the app module (I have another module for the di stuff) and it is working for me (Android Gradle plugin 4.0.0 and kotlin 1.4-M2)
I tried and it is not working for fragments too
I think this is a design issue of Dagger Hilt.
Hilt uses a monolithic component system.
https://dagger.dev/hilt/monolithic
Therefore, all classes defined in components are referenced by the generated MyApplication_HiltComponents
class.
I believe this is incompatible with DFM that loads classes dynamically.
There's documentation on Hilt and DFM now at https://developer.android.com/training/dependency-injection/hilt-multi-module#dfm
In general though, because we're built off of subcomponents and monolithic components you won't be able to use the standard Hilt mechanisms like @AndroidEntryPoint
with DFM.
Hmmm, too bad.
@Chang-Eric
Can't we at least use @ViewModelInject
and assisted SavedStateHandle with DFM?
Unfortunately, no. @ViewModelInject
uses the Hilt ActivityRetainedComponent
which is monolithic, so any @ViewModelInject
class in your DFM won't be recognized.
Thanks for your comments.
In summary, I updated my sample project. https://github.com/yamasa/Hilt_DFM
Hi there, I have a dynamic module called home that has a frag using @AndroidEntryPoint but I'm getting this error:
java.lang.ClassCastException: DaggerGranitexApp_HiltComponents_SingletonC$FragmentCImpl cannot be cast to HomeFragment_GeneratedInjector
Can't use Hilt in dynamic modules yet?
@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel, Any, Any, Any>(
layoutId = R.layout.fragment_home
), IBaseView.NavigationInitializer {
merci merci
Versions:
I tried Dagger Hilt with Dynamic Feature Modules. Here is a sample project: https://github.com/yamasa/Hilt_DFM
But, unfortunately, Dagger Hilt doesn't work for Activities in DFM. It crashes with the following exception:
Does Dagger Hilt currently support Dynamic Feature Modules? If not, is there a plan to support it?