kotlin 错误:[Hilt]在抽象模块com.example.weathersforecast.di.ApiModule中找到未实现的抽象方法[provideOpenWeatherApi()]

u2nhd7ah  于 2023-03-24  发布在  Kotlin
关注(0)|答案(1)|浏览(135)

我正在开发一个Android应用程序使用喷气背包撰写和匕首刀柄,但当我运行项目,我得到以下错误

ApiModule.java:8: error: [Hilt]
public abstract interface ApiModule {
                ^
  Found unimplemented abstract methods, [provideOpenWeatherApi()], in an abstract module, com.example.weathersforecast.di.ApiModule. Did you forget to add a Dagger binding annotation (e.g. @Binds)?
  [Hilt] Processing did not complete. See error above for details.

AppModule.kt下

@Module
@InstallIn(SingletonComponent::class)
interface ApiModule {
    @Singleton
    @Provides
    fun provideOpenWeatherApi(): WeatherApi {
        return Retrofit.Builder()
            .baseUrl(Constants.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
            .create(WeatherApi::class.java)

    }
}

我想知道我在哪里犯了错误我已经尝试了所有stackoverflow的答案它没有解决我的问题

pod7payv

pod7payv1#

将AppModule从接口更改为对象,解决了我的问题

相关问题