androidandroid-studiogradleandroid-roomgradle-dependencies

Why androidx.room.RoomDatabase is not recognised?


I'm learning modularity and in one of my modules androidx.room.* is not recognised. Downgrading Room version helps only with @Database annotation. Also, module seems to not see Room.roomKtx implementation because quick help suggest adding this implementation to build.gradle. My kotlin version is 1.6.21

ProfileDatabase.kt

import androidx.room.Database
import androidx.room.RoomDatabase
import com.example.modules.Gift
import com.example.modules.Profile

@Database(
    entities = [Profile::class, Gift::class],
    version = 1
)
abstract class ProfileDatabase: RoomDatabase() {
    abstract val profileDao: ProfileDao

    companion object {
        const val DATABASE_NAME = "profile_db"
    }
}

build.gradle(:profileDatabase)

apply {
    from("$rootDir/library-build.gradle")
    plugin 'kotlin-kapt'
}

dependencies {
    implementation(project(':modules'))
    implementation Kotlinx.coroutinesCore

    implementation Room.runtime
    implementation Room.roomKtx
    kapt Room.compiler

}

Room.kt

object Room {
    private const val roomVersion = "2.4.2"
    const val runtime = "androidx.room:room-runtime:$roomVersion"
    const val compiler = "androidx.room:room-compiler:$roomVersion"
    const val roomKtx = "androidx.room:room-ktx:$roomVersion"
}

Solution

  • The problem was a wrong "module type". I used apply plugin:'java-library',
    but should use apply plugin:'com.android.library'.