https://kotlinlang.org logo
#dagger
Title
# dagger
h

Hovhannes

08/13/2021, 1:35 PM
Hello, everybody. How can I fix this issue. java.lang.String cannot be provided without an @Inject constructor or an @Provides-annotated method. Thanks in advance.
Copy code
@Singleton
@Provides
fun provideAuthApi(
    remoteDataSource: RemoteDataSource,
    string: String
): AuthApi {
    return remoteDataSource.buildApi(AuthApi::class.java, string)
}

@Singleton
@Provides
fun provideUserApi(
    remoteDataSource: RemoteDataSource,
   string: String
): UserApi {
    return remoteDataSource.buildApi(UserApi::class.java, string)
}
k

knthmn

08/13/2021, 2:34 PM
For Dagger to provide
AuthApi
and
UserApi
, it needs to get a
String
which you have not provided.
Copy code
@Provides
fun provideStringForApi(/* dependency for the string */): String = /* return the string */
👍 1
It is hard to say what
string
actually is due to your naming, however it is not recommended to have something as generic as
String
in your dependency graph without specifying it with a
Qualifier
. https://developer.android.com/training/dependency-injection/hilt-android#multiple-bindings
👍 1
97 Views