Koin: Room injection with KOIN not working

Created on 7 Jun 2018  路  2Comments  路  Source: InsertKoinIO/koin

I am trying to use the Room persistence library in my application but I have trouble with injection using KOIN. Does someone have an experience with such integration? I followed this TUTORIAL but I ended up with the following exception:

org.koin.error.DependencyResolutionException: Cyclic call while resolving Bean[class=com.freyja.client.database.RecordDatabase]. Definition is already in resolution in current call

The other exception I am getting when trying to use my Dao inside an activity is as follows:

W/System.err: java.lang.RuntimeException: cannot find implementation for com.app.client.database.RecordDatabase. RecordDatabase_Impl does not exist

I am the following definitions:

@Database(entities = [Record::class], version = 1)
abstract class RecordDatabase: RoomDatabase() {

    abstract fun recordDao(): RecordDao

}

@Dao
interface RecordDao {

    @Query("SELECT * from record WHERE recordId= :recordId LIMIT 1")
    fun get(recordId: Int): Record

}

and my Koin modules definition contains:

bean { Room.databaseBuilder(get(), RecordDatabase::class.java, "record-db")
                .build() }
bean { get<RecordDatabase>().recordDao() }

dependencies:

def koinVersion = "0.9.3"
implementation "org.koin:koin-android:$koinVersion"
implementation "org.koin:koin-android-architecture:$koinVersion"
androidTestImplementation "org.koin:koin-test:$koinVersion"

def roomVersion = "1.1.0"
implementation "android.arch.persistence.room:runtime:$roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
testImplementation "android.arch.persistence.room:testing:$roomVersion"

Most helpful comment

I resolved my problem with using kapt "android.arch.persistence.room:compiler:$roomVersion" instead of annotationProcessor. It seems that it was a Koltin issue after all.

All 2 comments

I resolved my problem with using kapt "android.arch.persistence.room:compiler:$roomVersion" instead of annotationProcessor. It seems that it was a Koltin issue after all.

ok cool 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakuenjery picture dakuenjery  路  4Comments

fmobus picture fmobus  路  4Comments

guymclean picture guymclean  路  3Comments

TedHoryczun picture TedHoryczun  路  4Comments

iRYO400 picture iRYO400  路  3Comments