sqlcipher / sqlcipher-android

SQLCipher for Android provides an interface to SQLCipher databases on the Android platform.
Other
128 stars 19 forks source link

NullPointerException with the sample implementation with Room #40

Closed cergo123 closed 5 months ago

cergo123 commented 5 months ago

I am implementing the following Db class:

@Database(entities = [Account::class, SMS::class], version = 4, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
    abstract fun accountDao(): AccountDao
    abstract fun smsDao(): SMSDao
    companion object {
        fun getInstance(context: Context): AppDatabase {
            System.loadLibrary("sqlcipher")
            val passphrase = EncryptedPrefs(context).getDBKey()
            val databaseFile = context.getDatabasePath("system.db")
            val factory = SupportOpenHelperFactory(passphrase?.toByteArray(StandardCharsets.UTF_8))
            val db = databaseBuilder(context, AppDatabase::class.java, databaseFile.absolutePath)
                .openHelperFactory(factory)
                .build()
            return db
        }
    }
}

I get this error in any call to it:

java.lang.NullPointerException
at androidx.room.Room.getGeneratedImplementation(Room.kt:42)
at androidx.room.RoomDatabase$Builder.build(RoomDatabase.kt:1347)
at AppDatabase$Companion.getInstance(AppDatabase.kt:28)

I tried with the latest versions of room and sqlite and also the versions in the test in this repo but it is the same error:

room = "2.5.0"
sqlcipher = "4.6.0"
sqlite = "2.2.0"
cergo123 commented 5 months ago

After some checking, it was related to my Room implementation, not related to SQLCipher