'DaggerHilt Multi Modular Project Cannot access class issue
I have created a Multi-Modular project in android with dagger implementation. my sub module structure for data module is below.
When ever I try to access method of my NewsApiInterface from NewsDetailsImpl inside testRepo() method and on compile time I get the error
Cannot access class 'retrofit2.Response'. Check your module classpath for missing or conflicting dependencies
Module:
data (Module) repository (Implementation Module) network(API Service Module) cache (Database Module)
repository Module -> datasource
class NewsDetailsImpl @Inject constructor(
val db: NewsDatabase,
val service: NewsApiInterface
) : NewsDetailsRepository {
override suspend fun fetchNewsDetail(): Flow<News> = flow{
}
override suspend fun fetchNewsList(
query: String,
limitStart: String,
limitEnd: String
): Flow<List<News>> = flow {
}
fun testRepo(query: String){
val news = service.getNews(query)
}
}
repository module -> di
@Module
@InstallIn(SingletonComponent::class)
class RepositoryModule {
@Singleton
@Provides
fun provideNewsRepository( db: NewsDatabase,
service: NewsApiInterface
): NewsDetailsRepository {
return NewsDetailsImpl(db,service)
}
}
data module -> network module -> di
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun providesNewsService() : NewsApiInterface {
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.client(
OkHttpClient.Builder()
.addInterceptor { chain ->
val url = chain
.request()
.url
.newBuilder()
.addQueryParameter("apiKey", NetworkConstants.API_KEY)
.build()
chain.proceed(chain.request().newBuilder().url(url).build())
}
.build()
)
.baseUrl(BASE_URL)
.build()
return retrofit.create(NewsApiInterface::class.java)
}
}
data module -> network module
interface NewsApiInterface {
@GET("everything")
public fun getNews(@Query("q") query: String): Response<NewsDto>
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
