Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Component (unscoped) may not reference scoped bindings

I've recently started using dagger-2 with kotlin. Unfortunately I have ecnountered a problem with sumbcomponants and I have trouble understanding why I get this gradle error:

...NetComponent (unscoped) may not reference scoped bindings:
@dagger.Subcomponent(modules = 
{com.example.kremik.cryptodroid.di.module.NetModule.class})
@Singleton @Provides com.example.kremik.cryptodroid.data.remote.CMCService com.example.kremik.cryptodroid.di.module.NetModule.providesCMCService(retrofit2.Retrofit)
@Singleton @Provides retrofit2.Retrofit com.example.kremik.cryptodroid.di.module.NetModule.providesRetrofit()
@org.jetbrains.annotations.NotNull @Singleton @Provides com.example.kremik.cryptodroid.data.service.CurrencyDataPresenter com.example.kremik.cryptodroid.di.module.NetModule.providesCurrencyDataPresenter(com.example.kremik.cryptodroid.data.local.CurrenciesProvider, com.example.kremik.cryptodroid.ui.LivePrices.LivePricesPresenter)

Module:app

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
    applicationId "com.example.kremik.cryptodroid"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner     
"android.support.test.runner.AndroidJUnitRunner"
}
configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),     
'proguard-rules.pro'
    }
}
//    dataBinding {
//        enabled = true
//    }
kapt {
    generateStubs = true
}

}
dependencies {
 (...)
//Dagger2
implementation 'com.google.dagger:dagger:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
implementation 'com.google.dagger:dagger-android-processor:2.11'
kapt 'com.google.dagger:dagger-compiler:2.11'
(...)
}

NetModule: @Module class NetModule(private val BASE_URL: String) {

@Provides
@Singleton
fun providesCurrencyDataPresenter(provider: CurrenciesProvider,
                                  pricesPresenter: LivePricesPresenter) =
        CurrencyDataPresenter(provider, pricesPresenter)

@Provides
@Singleton
fun providesRetrofit() = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())
        .build()

@Provides
@Singleton
fun providesCMCService(retrofit: Retrofit) = 
retrofit.create(CMCService::class.java)
}

NetComponent:

@Subcomponent(modules = arrayOf(NetModule::class))
interface NetComponent {
fun inject(service: CurrencyDownloaderService)
}

Does anyone know what could be the issue ?

like image 436
Kremik13 Avatar asked Sep 13 '17 10:09

Kremik13


1 Answers

Put @Singleton with your Component

@Singleton
@Subcomponent(modules = arrayOf(NetModule::class))
interface NetComponent {
fun inject(service: CurrencyDownloaderService)
}
like image 55
Dipendra Sharma Avatar answered Nov 20 '22 18:11

Dipendra Sharma