-1

whenever i try to run the application i am facing this error:

error: [Dagger/MissingBinding] api.PrayerTimesInterface cannot be provided without an @Provides-annotated method.

and this is the interface:

    @GET("calendar")
suspend fun getPrayerTimes(
    @Query("latitude") latitude: Double,
    @Query("longitude") longitude: Double,
    @Query("method") method: Int,
    @Query("month") month: Int,
    @Query("year") year: Int,
): Response<PlayerTime>

@GET("calendarByAddress")
suspend fun getPrayerAddress(
    @Query("address") address: String,
    @Query("method") method: Int,
    @Query("month") month: Int,
    @Query("year") year: Int,
): Response<PlayerTime>
}

i tried to add "@Provides" but still facing the same error. the same code available in different version of the app and it's working fine.

i tried the solution here: How to fix "cannot be provided without an @Provides-annotated method" error in dagger2 library

but it didn't work for me

did i do anything wrong here?

user2
  • 59
  • 1
  • 11
  • You need to add a provider method for `PrayerTimesInterface` in your network module or whichever module you are using for it .https://developer.android.com/training/dependency-injection/dagger-android – ADM Jun 04 '21 at 06:13

2 Answers2

2

Interface classes cannot be directly injected as they do not have constructors. I suppose you are using the PrayerTimesInterface with Retrofit. So inject PrayerTimesInterface with Retrofit's create method.

In module class

@Provides
internal fun providesPrayerTimes(): PrayerTimesInterface {
        return Retrofit.Builder().build().create(PrayerTimesInterface::class.java)
    }

You can also create Retrofit injection with all the options required and take it in providesPrayerTimes method to create PrayerTimesInterface

Nataraj KR
  • 1,001
  • 10
  • 22
0

For some one it may help.

Make sure you bind your implementation and interface in module kotlin file.

in the kotlin file which marked with @module annotation, would be having all bindings. 
In these bindings you need to mention the newly created interface and its implementation.
GvSharma
  • 2,632
  • 1
  • 24
  • 30