'Dynamic feature module with Hilt
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
Solution 1:[1]
You can continue to use Hilt in your app when you have dynamic feature modules. Hilt currently provides some basic functionality to inject bindings into dynamic features, but ultimately you need to use Dagger to connect your shared module dependencies to your Hilt dependency graph and use Dagger multibindings to build a generic solution for your ViewModel injection.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shawn Fetanat |
