小编Far*_*ary的帖子

@InstallIn注释的类也必须用@Module或@EntryPoint错误注释

我不知道为什么我收到“@InstallIn 注释的类还必须用 @Module 或 @EntryPoint 注释:com.example.newsapp.di.AppModule [Hilt] 处理未完成。有关详细信息,请参阅上面的错误。” 错误。我使用教程编写了这段代码,导师的代码(与我的完全相同)工作正常。`

@Module
@InstallIn(SingletonComponent::class)
object AppModule {
  @Provides
    fun baseURL() = BASE_URL

    @Provides
    fun logging() = HttpLoggingInterceptor()
        .setLevel(HttpLoggingInterceptor.Level.BODY)

    @Provides
    fun okHttpClient() = okhttp3.OkHttpClient.Builder()
        .addInterceptor(logging())
        .build()


    @Provides
    @Singleton
    fun provideRetrofit(baseUrl: String): NewsService =
        Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .client(okHttpClient())
            .build()
            .create(NewsService::class.java)}`
Run Code Online (Sandbox Code Playgroud)

android kotlin dagger-hilt

5
推荐指数
1
解决办法
1136
查看次数

标签 统计

android ×1

dagger-hilt ×1

kotlin ×1