// LoginModuleDependencies.kt - File in the app module.@EntryPoint@InstallIn(SingletonComponent::class)interfaceLoginModuleDependencies{@AuthInterceptorOkHttpClientfunokHttpClient():OkHttpClient}
Java
// LoginModuleDependencies.java - File in the app module.@EntryPoint@InstallIn(SingletonComponent.class)publicinterfaceLoginModuleDependencies{@AuthInterceptorOkHttpClientOkHttpClientokHttpClient();}
// LoginComponent.kt - File in the login module.@Component(dependencies=[LoginModuleDependencies::class])interfaceLoginComponent{funinject(activity:LoginActivity)@Component.BuilderinterfaceBuilder{funcontext(@BindsInstancecontext:Context):BuilderfunappDependencies(loginModuleDependencies:LoginModuleDependencies):Builderfunbuild():LoginComponent}}
Java
// LoginComponent.java - File in the login module.@Component(dependencies=LoginModuleDependencies.class)publicinterfaceLoginComponent{voidinject(LoginActivityloginActivity);@Component.BuilderinterfaceBuilder{Buildercontext(@BindsInstanceContextcontext);BuilderappDependencies(LoginModuleDependenciesloginModuleDependencies);LoginComponentbuild();}}
// LoginAnalyticsAdapter.kt - File in the login module.classLoginAnalyticsAdapter@Injectconstructor(@AuthInterceptorOkHttpClientokHttpClient:OkHttpClient){...}
Java
// LoginAnalyticsAdapter.java - File in the login module.publicclassLoginAnalyticsAdapter{privatefinalOkHttpClientokHttpClient;@InjectLoginAnalyticsAdapter(@AuthInterceptorOkHttpClientOkHttpClientokHttpClient){this.okHttpClient=okHttpClient;}...}
// LoginActivity.kt - File in the login module.classLoginActivity:AppCompatActivity(){@InjectlateinitvarloginAnalyticsAdapter:LoginAnalyticsAdapteroverridefunonCreate(savedInstanceState:Bundle?){DaggerLoginComponent.builder().context(this).appDependencies(EntryPointAccessors.fromApplication(applicationContext,LoginModuleDependencies::class.java)).build().inject(this)super.onCreate(savedInstanceState)...}}
Java
// LoginActivity.java - File in the login module.publicclassLoginActivityextendsAppCompatActivity{@InjectLoginAnalyticsAdapterloginAnalyticsAdapter;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){DaggerLoginComponent.builder().context(this).appDependencies(EntryPointAccessors.fromApplication(getApplicationContext(),LoginModuleDependencies.class)).build().inject(this);super.onCreate(savedInstanceState);...}}
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Hilt in multi-module apps\n\nHilt code generation needs access to all the Gradle modules that use Hilt. The\nGradle module that compiles your\n[`Application`](/reference/android/app/Application) class needs to have all Hilt\nmodules and constructor-injected classes in its transitive dependencies.\n\nIf your multi-module project is composed of regular Gradle modules, then you can\nuse Hilt as described in [Dependency injection with\nHilt](/training/dependency-injection/hilt-android). However, this is not the\ncase with apps that include [feature\nmodules](/guide/app-bundle/dynamic-delivery#customize_delivery).\n| **Note:** For deep multi-module projects, consider enabling the `enableExperimentalClasspathAggregation` flag in your `build.gradle` file. Read more about it in the [Hilt documentation](https://dagger.dev/hilt/gradle-setup#classpath-aggregation).\n\nHilt in feature modules\n-----------------------\n\nIn feature modules, the way that modules usually depend on each other is inverted.\nTherefore, Hilt cannot process annotations in feature modules. You must\nuse [Dagger](/training/dependency-injection/dagger-basics) to perform\ndependency injection in your feature modules.\n\nYou must use component dependencies to solve this problem with feature modules. Follow\nthese steps:\n\n1. Declare an [`@EntryPoint` interface](/training/dependency-injection/hilt-android#not-supported) in the `app` module (or in any other module that can be processed by Hilt) with the dependencies that the feature module needs.\n2. Create a Dagger component that depends on the `@EntryPoint` interface.\n3. Use Dagger as usual in the feature module.\n\nConsider the example from the [Dependency injection with\nHilt](/training/dependency-injection/hilt-android) page. Suppose you add a\n`login` feature module to your project. You implement the login feature\nwith an activity called `LoginActivity`. This means that you can get bindings\nonly from the application component.\n\nFor this feature, you need an `OkHttpClient` with the `authInterceptor` binding.\n\nFirst, create an `@EntryPoint` interface installed in the `SingletonComponent`\nwith the bindings that the `login` module needs: \n\n### Kotlin\n\n```kotlin\n// LoginModuleDependencies.kt - File in the app module.\n\n@EntryPoint\n@InstallIn(SingletonComponent::class)\ninterface LoginModuleDependencies {\n\n @AuthInterceptorOkHttpClient\n fun okHttpClient(): OkHttpClient\n}\n```\n\n### Java\n\n```java\n// LoginModuleDependencies.java - File in the app module.\n\n@EntryPoint\n@InstallIn(SingletonComponent.class)\npublic interface LoginModuleDependencies {\n\n @AuthInterceptorOkHttpClient\n OkHttpClient okHttpClient();\n}\n```\n\nTo perform field injection in the `LoginActivity`, create a Dagger\ncomponent that depends on the `@EntryPoint` interface: \n\n### Kotlin\n\n```kotlin\n// LoginComponent.kt - File in the login module.\n\n@Component(dependencies = [LoginModuleDependencies::class])\ninterface LoginComponent {\n\n fun inject(activity: LoginActivity)\n\n @Component.Builder\n interface Builder {\n fun context(@BindsInstance context: Context): Builder\n fun appDependencies(loginModuleDependencies: LoginModuleDependencies): Builder\n fun build(): LoginComponent\n }\n}\n```\n\n### Java\n\n```java\n// LoginComponent.java - File in the login module.\n\n@Component(dependencies = LoginModuleDependencies.class)\npublic interface LoginComponent {\n\n void inject(LoginActivity loginActivity);\n\n @Component.Builder\n interface Builder {\n Builder context(@BindsInstance Context context);\n Builder appDependencies(LoginModuleDependencies loginModuleDependencies);\n LoginComponent build();\n }\n}\n```\n\nOnce those steps are complete, use Dagger as usual in your feature module. For\nexample, you can use the bindings from the `SingletonComponent` as a\ndependency of a class: \n\n### Kotlin\n\n```kotlin\n// LoginAnalyticsAdapter.kt - File in the login module.\n\nclass LoginAnalyticsAdapter @Inject constructor(\n @AuthInterceptorOkHttpClient okHttpClient: OkHttpClient\n) { ... }\n```\n\n### Java\n\n```java\n// LoginAnalyticsAdapter.java - File in the login module.\n\npublic class LoginAnalyticsAdapter {\n\n private final OkHttpClient okHttpClient;\n\n @Inject\n LoginAnalyticsAdapter(\n @AuthInterceptorOkHttpClient OkHttpClient okHttpClient\n ) {\n this.okHttpClient = okHttpClient;\n }\n ...\n}\n```\n\nTo perform field injection, create an instance of the Dagger component\nusing the `applicationContext` to get the `SingletonComponent` dependencies: \n\n### Kotlin\n\n```kotlin\n// LoginActivity.kt - File in the login module.\n\nclass LoginActivity : AppCompatActivity() {\n\n @Inject\n lateinit var loginAnalyticsAdapter: LoginAnalyticsAdapter\n\n override fun onCreate(savedInstanceState: Bundle?) {\n DaggerLoginComponent.builder()\n .context(this)\n .appDependencies(\n EntryPointAccessors.fromApplication(\n applicationContext,\n LoginModuleDependencies::class.java\n )\n )\n .build()\n .inject(this)\n\n super.onCreate(savedInstanceState)\n ...\n }\n}\n```\n\n### Java\n\n```java\n// LoginActivity.java - File in the login module.\n\npublic class LoginActivity extends AppCompatActivity {\n\n @Inject\n LoginAnalyticsAdapter loginAnalyticsAdapter;\n\n @Override\n protected void onCreate(Bundle savedInstanceState) {\n DaggerLoginComponent.builder()\n .context(this)\n .appDependencies(\n EntryPointAccessors.fromApplication(\n getApplicationContext(),\n LoginModuleDependencies.class\n )\n )\n .build()\n .inject(this);\n\n super.onCreate(savedInstanceState);\n ...\n }\n}\n```\n\nFor more context on module dependencies in feature modules, see\n[Component dependencies with feature\nmodules](/training/dependency-injection/dagger-multi-module#dagger-dfm).\n\nFor more information about Dagger on Android, see [Using Dagger in Android\napps](/training/dependency-injection/dagger-android)."]]