Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

457
Vistas
Hilt dependency injection in multi-module project

I have two modules in my android app, app and data. data module contains retrofit dependency and app module depends on data module.

app/build.gradle:

implementation project(':data')

implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

data/build.gradle:

implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"

In data module, I have the following Hilt module:

@Module
@InstallIn(SingletonComponent::class)
internal object DataModule {

    @Singleton
    @Provides
    fun provideRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl(Constants.API_BASE_URL)
            .addConverterFactory(MoshiConverterFactory.create())
            .build()
    }

    @Singleton
    @Provides
    fun provideLoginApiService(retrofit: Retrofit): LoginApiService {
        return retrofit.create(LoginApiService::class.java)
    }

    @Singleton
    @Provides
    fun provideLoginRepository(loginRepository: LoginRepositoryImpl): LoginRepository {
        return loginRepository
    }

}

Here, LoginApiService and LoginRepositoryImpl are internal in data module and LoginRepository is public (in data module):

@Singleton
internal class LoginRepositoryImpl @Inject constructor(
    private val loginApiService: LoginApiService
) : LoginRepository {
    // ...
}

Now when I try to build the project, I get the following error:

DaggerMyApplication_HiltComponents_SingletonC.java:41: error: package retrofit2 does not exist
import retrofit2.Retrofit;

The error goes away if I add retrofit dependency in my app module which I don't want to do.

What's happening here and how can I resolve this error without adding data module dependencies in app module?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda