I'm trying out a new architecture with multi-module and DI though Hilt, I have the following modules:
When I start the app I'm getting java.lang.RuntimeException: Cannot create an instance of class HomeViewModel
App module
@AndroidEntryPoint
class MainActivity: AppCompatActivity()
FeatureHome
class HomeFragment: Fragment() {
private val viewModel: HomeViewModel by viewModels()
...
}
@HiltViewModel
class HomeViewModel @Inject constructor(): ViewModel {
....
}
I'm not sure what to do to resolve this. Should my HomeFragment also have @AndroidEntryPoint
?
Your Fragment
has to be marked with the annotation @AndroidEntryPoint
in order to tell Hilt to inject instances in your Fragment. (documentation)