我不知道为什么我收到“@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)