I am trying to follow the Hilt migration guide here: https://dagger.dev/hilt/migration-guide.html
And have annotated all my modules with:
@InstallIn(SingletonComponent::class)
However I am running into issues with my "Contributor" Modules for services, fragments and activities.
I have one module for each,
@Module
@InstallIn(SingletonComponent::class)
abstract class FragmentContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyFragment(): MyFragment
}
@Module
@InstallIn(SingletonComponent::class)
abstract class ActivityContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyActivity(): MyActivity
}
@Module
@InstallIn(SingletonComponent::class)
abstract class ServiceContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyService(): MyService
}
During compile I am getting errors for each one of the "contribute" functions:
com.test.ActivityContributorModule_ContributeMyActivity$defaultsDebug is missing an @InstallIn annotation. If this was intentional, see https://dagger.dev/hilt/compiler-options#disable-install-in-check for how to disable this check.
I have also tried to use ServiceComponent::class, FragmentComponent::class and ActivityComponent::class for each Module with no luck. I am trying to migrate the project in pieces so I don't think I can remove these until everything is upgraded to Hilt.
Any ideas?
The answer is here:
Warning: Modules that are not annotated with @InstallIn are not used by Hilt. Hilt by default raises an error when unannotated modules are found, but this error can be disabled.
Was not 100% clear to me at first, but the contributor modules I have for services/fragments/activities are only used with Dagger, not Hilt. So if you are trying to migrate you project in pieces you can leave those module as is until you start to provide Hilt entry points for your services/fragments/activities. However if you do that, you will need to tell Hilt to ignore the error it throws for missing @InstallIn.
More info on how to disable that here:
https://dagger.dev/hilt/compiler-options.html#disable-install-in-check
By default, Hilt checks @Module classes for the @InstallIn annotation and raises an error if it is missing. This is because if someone accidentally forgets to put @InstallIn on a module, it could be very hard to debug that Hilt isn’t picking it up.
This check can sometimes be overly broad though, especially if in the middle of a migration. To turn off this check, this flag can be used:
-Adagger.hilt.disableModulesHaveInstallInCheck=true.
Alternatively, the check can be disabled at the individual module level by annotating the module with @DisableInstallInCheck.