Home > Mobile >  LocalDatabase_Impl does not exist
LocalDatabase_Impl does not exist

Time:05-16

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

abstract fun aepsBankTokenDao(): AepsBankTokenDao

companion object {
    private var DATABASE_INSTANCE: LocalDatabase? = null
    private const val DB_NAME = "wla.db"

  fun getInstance(): LocalDatabase? {

        if (DATABASE_INSTANCE == null) {

            synchronized(LocalDatabase::class) {
                DATABASE_INSTANCE = Room.databaseBuilder(
                    AepsSdk.instance?.context!!,
                        LocalDatabase::class.java, DB_NAME).allowMainThreadQueries().build()
            }
        }
        return DATABASE_INSTANCE
    }
}
}



@Dao
interface AepsBankTokenDao {

@Insert (onConflict = OnConflictStrategy.REPLACE)
fun insert(aepsBankTokenModel: AepsBankTokenModel)

@Update
fun update(aepsBankTokenModel: AepsBankTokenModel)

@Delete
fun delete(aepsBankTokenModel: AepsBankTokenModel)

@Query("delete from aeps_bank_token_model")
fun deleteAllNotes()

@Query("select * from aeps_bank_token_model ")
fun getAllAepsBankToken(): LiveData<List<AepsBankTokenModel>>

@Query("SELECT * FROM `aeps_bank_token_model` WHERE bankId == :bankId AND userId == :userId ")
fun getAepsBankTokenObj(bankId : String, userId : String ): AepsBankTokenModel

}

@Entity(tableName = "aeps_bank_token_model")
data class AepsBankTokenModel(
    @SerializedName("AT")
    var accessToken: String,
    @SerializedName("RT")
    var refreshToken: String,
    @SerializedName("BName")
    var bankName: String,
    @SerializedName("BId")
    var bankId: String,
    @SerializedName("createdBy")
    var userId: String,
    @SerializedName("ATExp")
    var accessTokenExpiry: String,
    @SerializedName("RTExp")
    var refreshTokenExpiry: String,
    var createdAt: String,
    var modifiedAt: String,
    @PrimaryKey(autoGenerate = true) var id: Int? = null)

all the above files are created in one module and accessing into another module using aar file but every time it gives below error

2022-05-15 23:39:04.895 15276-15276/com.a W/System.err: java.lang.RuntimeException: cannot find implementation for com.a.sdk.database.LocalDatabase. LocalDatabase_Impl does not exist 2022-05-15 23:39:04.895 15276-15276/com.a W/System.err: at androidx.room.Room.getGeneratedImplementation(Room.java:97) 2022-05-15 23:39:04.896 15276-15276/com.a W/System.err: at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1358) 2022-05-15 23:39:04.896 15276-15276/com.a W/System.err: at com.a.database.LocalDatabase$Companion.getInstance(LocalDatabase.kt:27) 2022-05-15 23:39

I used below dependencies

implementation 'androidx.room:room-runtime:2.3.0' annotationProcessor 'androidx.room:room-compiler:2.3.0'

and if I replace annotationProcessor with kapt it gives below error app:kaptDebugKotlin

CodePudding user response:

Remove these abstract keywords, then you don't have to worry about the lack of implementation.
Classes annotated with Room annotations must be instance-able, but abstract classes are not.

CodePudding user response:

The problem is in your build.gradle file, you should enable kotlin-kapt and add room to your dependency like this:

plugins {
    id 'kotlin-kapt'
}

android {
   
   ...

}

dependencies {

    ...

    implementation("androidx.room:room-runtime:2.4.2")
    kapt("androidx.room:room-compiler:2.4.2")


}
  • Related