Migrate single db with two frame work (native sqlite , Room databse)

im using room db and sqlite to point to single db file in my android project , so the base database is native sqlite and the room is exact duplicat of the sqlite tahe means same entites , version so how can i migrate to this database structure in to sqlite db im tried lot of methods but non of this work how can i do this …
when i trying to use
implementation ‘net.zetetic:sqlcipher-android:4.5.6@aar’

implementation 'androidx.sqlite:sqlite-ktx:2.4.0'

and im getting the error

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class com.myapp.MyDatabase, unresolved supertypes: net.zetetic.database.sqlcipher.SQLiteOpenHelper

and also im trying
implementation ‘net.zetetic:sqlcipher-android:4.5.6’

implementation ‘androidx.sqlite:sqlite-ktx:2.4.0’

in this case my first compileations is work but when i close and open the app , app is crash because of room data base is not found the db:
the erro message is like "its not a data base "

Hi @Edward_Sundarsingh,

Are you attempting to convert a plaintext SQLite database to SQLCipher encrypted database? If so, you will want to try doing this outside of Room (though you can still use SQLCipher for Android to perform that process using sqlcipher_export(...), see example #1). Once you have that done, you can use the SupportOpenHelperFactory from SQLCipher for Android when building your Room database instance.

1 Like

i solve the above issue that is happen because of the jar fille is stored in my gradle cash so i removed it
but still i encounter this issu

java.lang.UnsatisfiedLinkError: No implementation found for void net.sqlcipher.database.SQLiteDatabase.dbopen(java.lang.String, int) (tried Java_net_sqlcipher_database_SQLiteDatabase_dbopen and Java_net_sqlcipher_database_SQLiteDatabase_dbopen__Ljava_lang_String_2I) - is the library loaded, e.g. System.loadLibrary?
at net.sqlcipher.database.SQLiteDatabase.dbopen(Native Method)
at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2597)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1214)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1186)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1135)
at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1089)

Hi @Edward_Sundarsingh,

From that stack trace it appears you are referencing android-database-sqlcipher, however, this library has been deprecated in favor of sqlcipher-android. We have some instructions for migrating to the latest library here:

https://www.zetetic.net/sqlcipher/sqlcipher-for-android-migration/

im read the doc and i change my impl but still i encounter this issue
and im don this in my MYAPP class. onCreate {
System.loadLibrary(“sqlcipher”);
}

java.lang.UnsatisfiedLinkError: No implementation found for long net.zetetic.database.sqlcipher.SQLiteConnection.nativeOpen(java.lang.String, int, java.lang.String, boolean, boolean) (tried Java_net_zetetic_database_sqlcipher_SQLiteConnection_nativeOpen and Java_net_zetetic_database_sqlcipher_SQLiteConnection_nativeOpen__Ljava_lang_String_2ILjava_lang_String_2ZZ) - is the library loaded, e.g. System.loadLibrary?
at net.zetetic.database.sqlcipher.SQLiteConnection.nativeOpen(Native Method)
at net.zetetic.database.sqlcipher.SQLiteConnection.open(SQLiteConnection.java:226)
at net.zetetic.database.sqlcipher.SQLiteConnection.open(SQLiteConnection.java:202)
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:475)
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.open(SQLiteConnectionPool.java:189)
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.open(SQLiteConnectionPool.java:181)
at net.zetetic.database.sqlcipher.SQLiteDatabase.openInner(SQLiteDatabase.java:1028)
at net.zetetic.database.sqlcipher.SQLiteDatabase.open(SQLiteDatabase.java:1013)
at net.zetetic.database.sqlcipher.SQLiteDatabase.openDatabase(SQLiteDatabase.java:840)
at net.zetetic.database.sqlcipher.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:359)
at net.zetetic.database.sqlcipher.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:278)

Hi @Edward_Sundarsingh,

Are you invoking:

System.loadLibrary("sqlcipher");

before you attempt to interface with any of the SQL classes including the SQLiteOpenHelper?

Yes @developernotes I don this in my onCreate
Application class . And one thing to note , my one of the dependency is used android-database-sqlcipher , the deprecated one is any issue?

Im decided to change to use

mplementation 'net.zetetic:android-database-sqlcipher:4.5.4@aar'
implementation 'androidx.sqlite:sqlite:2.2.0'

for the older implementation so i encounter the issue that is → im using sqlite data base and room data base , both is shared singe db file in my local storage so both data base frame work have exacte entites , version . so im implement an sql cipher in my room as well as sqlite (change androidx.database to net.sqlcipher ) and i use give SupportFactory to my room but after i compile the code my room database query is work well but my Cipher SQLite (native Sqlite ) Query is throw an error

net.sqlcipher.database.SQLiteException: no such table: user: , while compiling: INSERT OR REPLACE  INTO user(......) ```

and also this

net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

when i see the stack trace its show , where i call the Sqlitecipher(Native Sqlite ) query , but my room query is work well .

Hi @Edward_Sundarsingh,

We strongly suggest against using android-database-sqlcipher and sqlcipher-android together within an application, there is a strong potential for corruption. You will have to choose one.

yes im decied to use android-database-sqlcipher , im implement the custom support factory

class CustomSupportHelper(
    private val configuration: SupportSQLiteOpenHelper.Configuration,
    private val passphrase: ByteArray
) : SupportSQLiteOpenHelper {

    private val delegate: SQLiteDatabaseOpenHelper

    init {
        delegate = MyEncriptedNativeSqlite(configuration.context, configuration.name, passphrase, null)
    }

    override fun getDatabaseName(): String {
        return delegate.databaseName
    }

    override fun setWriteAheadLoggingEnabled(enabled: Boolean) {
        delegate.setWriteAheadLoggingEnabled(enabled)
    }

    override fun getWritableDatabase(): SupportSQLiteDatabase {
        return delegate.getWritableDatabase(passphrase)
    }

    override fun getReadableDatabase(): SupportSQLiteDatabase {
        return delegate.getReadableDatabase(passphrase)
    }

    override fun close() {
        delegate.close()
    }

} 
class CustomSupportFactory(private val passphrase: ByteArray) : SupportSQLiteOpenHelper.Factory {
    override fun create(configuration: SupportSQLiteOpenHelper.Configuration): SupportSQLiteOpenHelper {
        return CustomSupportHelper(configuration, passphrase)
    }
}

but im facing an issue

net.sqlcipher.database.SQLiteException: no such table: room_table_modification_log: INSERT OR IGNORE INTO room_table_modification_log VALUES(0, 0) why this error is occure after im implement my customSupportOpenHelper


Hi @Edward_Sundarsingh,

That appears to be a Room error. What happens when you pull the database off device and examine it with DB Browser for SQLite [1]? Is the table room_table_modification_log present?


  1. Index of /latest/ ↩︎

No this table is not created but my db is encrypted.

Can you give and documents for this issue

Hi @Edward_Sundarsingh,

We had a report of a similar error here, however, this was with an older version of sqlcipher-android. This issue was fixed (with confirmation from the reporter) in the 4.5.3 release.