Error resolving method 'loadLibs' in 'SQLiteDatabase'(SQLiteDatabase.loadLibs();)
I am trying to use SQLCipher for android studio, although I have added library to dependencies I get this error.
(DBHelper class)
public DBHelper(Context context) {
super(context, DB_Name, null, DATABASE_VERSION);
this.myContext = context;
this.DB_Path = "/data/data/" + context.getPackageName() + "/" + "databases/";
Log.e("Path 1", DB_Path);
SQLiteDatabase.loadLibs();
}
I have added this libraries:
implementation 'net.zetetic:sqlcipher-android:4.5.4@aar'
implementation 'androidx.sqlite:sqlite:2.2.0'
(and also tried older library)
import net.zetetic.database.sqlcipher.SQLiteDatabase;
I have synced project, and built gradle, and tried "Invalidate caches" and Clean and Rebuild project, but problem persists.
So after struggling with a similar issue for most of a day I think I have a solution...
My error started when I needed to migrate an app from using
net.zetetic:android-database-sqlcipher:4.4.0(Deprecated) to the listed replacementnet.zetetic:sqlcipher-android:4.5.5which then resulted in the app crashing on open with the exceptionjava.lang.UnsatisfiedLinkError: No implementation found for long net.zetetic.database.sqlcipher.SQLiteConnection.nativeOpen(...All of the answers I was able to find only mention the need to have a call to
SQLiteDatabase.loadLibs()in the app but my app did not have that before this update and was working fine. Further the new librarynet.zetetic:sqlcipher-android:4.5.5does not have any such method (I checked the source repo)... so after some more searching I found another method used in one of the test clases in the library source (net.zetetic.database.sqlcipher_cts.RoomUpsertTest)which is
System.loadLibrary("sqlcipher");So I added that into my DB initialisation and now the app runs fine again.