2

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.

0

2 Answers 2

2

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 replacement net.zetetic:sqlcipher-android:4.5.5 which then resulted in the app crashing on open with the exception java.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 library net.zetetic:sqlcipher-android:4.5.5 does 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.

Sign up to request clarification or add additional context in comments.

Comments

0

I´m late to the party, but I was able to fix it with the following build.grade configuration

packagingOptions {
    jniLibs {
        useLegacyPackaging = true // this is to fix an issue with old and missing .so files like used in sqlCipher
    }
    resources {
        excludes += ['META-INF/LICENSE.txt', 'META-INF/NOTICE.txt', 'META-INF/rxjava.properties', 'META-INF/DEPENDENCIES', 'META-INF/INDEX.LIST']
    }
}

Looks like .so files may get messed up with new packaging structure on some devices.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.