I try to make my feature module as a dynamic feature module while I am using Hilt as dependency injection framework. I receive following exception :
caused by: java.lang.ClassCastException: com.android.sample.viaplay.DaggerViaplayApplication_HiltComponents_SingletonC$ActivityRetainedCImpl$ActivityCImpl$FragmentCI cannot be cast to com.android.sample.viaplay.feature.list.ui.DashboardFragment_GeneratedInjector
at com.android.sample.viaplay.feature.list.ui.Hilt_DashboardFragment.inject(Hilt_DashboardFragment.java:104)
at com.android.sample.viaplay.feature.list.ui.Hilt_DashboardFragment.onAttach(Hilt_DashboardFragment.java:55)
at androidx.fragment.app.Fragment.onAttach(Fragment.java:1783)
at com.android.sample.viaplay.feature.list.ui.Hilt_DashboardFragment.onAttach(Hilt_DashboardFragment.java:43)
I have used Dagger and not Dagger-Hilt in another sample and it worked as expected : https://github.com/alirezaeiii/SampleDaggerRx
Is it possible to use Dynamic feature module with Hilt? If yes, how can I solve above exception. You can find my source code at : https://github.com/AliRezaeiii/Hilt-MultiModule-Cache
As mentioned in the following link : Dagger Hilt doesn't work with Dynamic Feature Modules :
Hilt uses a monolithic component system which is incompatible with DFM that loads classes dynamically.