I have this issue when I try to use Kotlin and Dagger 2 .
"interface cannot be provided without an @Provides- or @Produces-annotated method.”
This is my Module class:
@Module
class MenuActivityModule(@NonNull private val menuActivity: MenuActivity) {
@Provides
@MenuActivityScope
fun provideGameScreenDimensions(application: Application) =
GameScreenDimension(application.resources)
@Provides
@MenuActivityScope
fun provideAudio() =
AndroidAudio(menuActivity)
@Provides
@MenuActivityScope
fun providePowerManager() =
menuActivity.getSystemService(Context.POWER_SERVICE) as PowerManager
@Provides
@MenuActivityScope
fun provideWakeLock(@NonNull powerManager: PowerManager) =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Preferences.APPLICATION_TAG)
}
This is a part of my Activity class, where I inject some variables with Dagger:
class MenuActivity : BaseActivity {
@Inject
lateinit var myAudio: Audio
@Inject
lateinit var wakeLock: PowerManager.WakeLock
@Inject
lateinit var apiService : ApiService
@Inject
lateinit var sharedPref : SharedPreferences
@Inject
lateinit var gameDimension : GameScreenDimension
init {
DaggerMenuActivityComponent.builder()
.menuActivityModule(MenuActivityModule(this))
.build()
.inject(this)
}
//more code
}
Audio.kt is interface and Dagger has problem to inject it. Inside the activity module I am returning AndroidAudio instance, which implements Audio interface. I am not sure what is the problem here. In Java I have had many times injection of interfaces and I never had this issue before. If somebody can help me I will be so happy. Thanks!