saquibansari
saquibansari

Reputation: 388

Room.databaseBuilder() cannot find Room dependencty even after importing from androidx.room.Room

Room.databaseBuilder() cannot find Room dependencty even after importing from androidx.room.Room. I have made a different Kotlin library for database and implemented dependency in gradle for Room.

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

All the other Room annotations are working correctly but still cannot find Room.

Upvotes: 2

Views: 83

Answers (1)

aiwithab
aiwithab

Reputation: 321

In my case, I made an Android library instead of java/kotlin.That solved my problem and don't forget to apply the plugin for kotlin-kapt in build Gradle. Also, try cleaning and rebuilding your project.

   plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

and add the following dependency for Room as described in the documentation.

dependencies {
  def room_version = "2.3.0"

  implementation "androidx.room:room-runtime:$room_version"
  kapt "androidx.room:room-compiler:$room_version"

  // optional - Kotlin Extensions and Coroutines support for Room
  implementation "androidx.room:room-ktx:$room_version"

  // optional - Test helpers
  testImplementation "androidx.room:room-testing:$room_version"
}

Upvotes: 2

Related Questions