SQLCipher integration problem

I am using SQLCipher with latest dependency by adding compile ‘net.zetetic:android-database-sqlcipher:3.5.1’ in app’s build.gradle file and other attributes of my gradle file are:

compileSdkVersion 23
buildToolsVersion “23.0.1”
defaultConfig{
minSdkVersion 14
targetSdkVersion 23
}

Compilation is done successfully but when running on app on device/Emulator with Android version 6.0 app gets crashed.

Following is the log from logcat.

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sqlTest.SQLCipherTestApp, PID: 3222
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.sqlTest.SQLCipherTestApp-1/base.apk”],nativeLibraryDirectories=[/data/app/com.sqlTest.SQLCipherTestApp-1/lib/x86, /vendor/lib, /system/lib]]] couldn’t find “libsqlcipher.so”
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:177)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:170)
at com.sqlTest.SQLCipherTestApp.activities.MyApplication.onCreate(MyApplication.java:35)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

To resolve this temporarly I have copied content of jni folder from build/intermediates/exploded-aar/net.zetetic/android-database-sqlcipher/3.5.1/jni and placed into the app/main/jniLibs folder.

Is this the correct way to do this or I am doing something wrong?

I am unable to find the exact tutorial on how to integrate the SQLCipher in Android Studio using dependency for Marshmallow device.

You are missing the @aar portion of the compile statement. Within the dependencies section of your application module, add the following:

compile 'net.zetetic:android-database-sqlcipher:3.5.1@aar'

Hello Developernotes,

I have changed to compile ‘net.zetetic:android-database-sqlcipher:3.5.1@aar’ and removed the jniLibs folder from app/main. I have cleaned the project and rebuild it. but still I am getting crash

Following is the logcat after change

06-29 20:04:54.007 1544-1544/com.sqlTest.SQLCipherTestApp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sqlTest.SQLCipherTestApp, PID: 1544
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.sqlTest.SQLCipherTestApp-2/base.apk”],nativeLibraryDirectories=[/data/app/com.sqlTest.SQLCipherTestApp-2/lib/arm, /vendor/lib, /system/lib]]] couldn’t find “libsqlcipher.so”
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:177)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:170)
at com.sqlTest.SQLCipherTestApp.activities.MyApplication.onCreate(MyApplication.java:35)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

For anyone using greendao and sqlcipher:
net.sqlcipher.database.SQLiteException: no such collation sequence: LOCALIZED:

Upgrade your greendao change your gradle to:
compile ‘org.greenrobot:greendao-encryption:2.2.2’
compile ‘net.zetetic:android-database-sqlcipher:3.5.1@aar’

Reference:

I am not using greendao in my application

Moreover following is the dependency list from by build.gradle file

dependencies {
compile project(‘:MyCustomLib’)
compile fileTree(include: [‘*.jar’], dir: ‘libs’)
compile ‘com.google.inject:guice:4.0-beta5:no_aop’
// Unit testing dependencies
androidTestCompile ‘junit:junit:4.12’
// Set this dependency if you want to use the Hamcrest matcher library
androidTestCompile ‘org.hamcrest:hamcrest-library:1.3’
// more stuff, e.g., Mockito
compile ‘com.android.support:design:23.3.0’
compile ‘com.android.support:cardview-v7:23.3.0’
compile ‘com.android.support:recyclerview-v7:23.3.0’
compile ‘com.android.support:multidex:1.0.1’
compile ‘com.mcxiaoke.volley:library:1.0.19’
compile ‘com.google.code.gson:gson:2.4’
compile ‘org.apache.wink.example:MultiPart:1.4’
compile ‘com.github.bumptech.glide:glide:3.6.1’
compile ‘com.google.android.gms:play-services:8.3.0’
compile ‘com.baoyz.swipemenulistview:library:1.3.0’
compile ‘com.google.android.gms:play-services-gcm:8.3.0’
compile ‘com.github.recruit-lifestyle:FloatingView:1.7’
compile(‘com.crashlytics.sdk.android:crashlytics:2.5.7@aar’) {
transitive = true;
}
compile(‘com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar’) {
transitive = true;
}
compile ‘net.zetetic:android-database-sqlcipher:3.5.1@aar’
}

I can assume that the issue is of sqlcipher dependency from logcat couldn’t find “libsqlcipher.so”

Hi @Dinesh

Since you have many third-party dependencies, it may be beneficial to create a secondary demo application, add SQLCipher for Android first, then slowly add back all of your additional dependencies to see where the conflict exists.

Hi @developernotes

I found its working perfectly on separate project where less dependencies used.
Thanks for the helping out from this issue and suggesting the different way.

Hi @developernotes

I have changes dependency to {compile ‘net.zetetic:android-database-sqlcipher:3.5.1@aar’}. Not its working fine in marshmallow device (Lava Pixel-v1). But when I run it on Nexus-5X (OS 6.0) and Yu Yureka Plus (OS 5.1.1) its getting crashed. I am attaching the logcat result from Yu Yureka:

--------- beginning of crash
09-05 17:05:31.865 7939-7939/com.nw.support E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nw.support, PID: 7939
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.nw.support-1/base.apk”],nativeLibraryDirectories=[/data/app/com.nw.support-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn’t find “libsqlcipher.so”
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:988)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:177)
at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:170)
at com.nw.support.activities.MyApplication.onCreate(MyApplication.java:35)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4591)
at android.app.ActivityThread.access$1600(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

@Dinesh the exception shows that your app has arm64 libraries but this is not supported by SQLCipher. You have to be sure you get rid of all 64-bit libraries if you use SQLCipher.

Hi Brodybits,

I really appriciate for your quick response. I will be thankful of you, If can can give some idea or indication in how to rid off this situation.

@Dinesh as I said you have to git rid of all 64-bit libraries. Look in the libs subdirectory of your project and look very carefully through all other dependencies. You may want to try the dependencies one at a time until you find out which one or ones have 64-bit libraries.

If this does not make sense please explain exactly which step does not make sense so others can help.

Unfortunately I am not so familiar with Eclipse, Maven, etc. so I don’t think I can help much further than this.

Disclaimer: I am not a part of the SQLCipher organization.

Thanks @Brodybits, to give me at-least one direction to resolve this issue.

Note: I am using android studio (Gradle Build) for my application.

I have sued some gradle dependencies and few jar files. I am listing all of these, if anybody has already worked on it and figured out the libraries using 64-bit binaries can help too.

JAR FILES:

commons-lang3-3.4.jar
httpclient-4.5.1.jar
httpcore-4.4.3.jar
httpmime-4.3.1.jar
ledatastream.jar

Gradle Dependencies

compile project(':MyCustomLib')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.inject:guice:4.0-beta5:no_aop'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.4'
compile 'org.apache.wink.example:MultiPart:1.4'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.baoyz.swipemenulistview:library:1.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.github.recruit-lifestyle:FloatingView:1.7'
compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
    transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar') {
    transitive = true;
}
compile 'net.zetetic:android-database-sqlcipher:3.5.1@aar'

@Dinesh I suggest you do the hard work yourself. Something like what @developernotes suggested before: create a test app with SQLCipher, make sure the encryption/decryption is working, and then add the other dependencies one at a time until you see which ones trigger the error. There may be more than one.

Some extra tips:

  • At every point where it does work keep a safe copy somewhere.
  • You may want to try all the com.android Gradle dependencies together, maybe SQLCipher will work with all of them. Same for the com.google dependencies.
  • If there are still a lot of dependencies you are not sure about, you may want to try a “divide and conquer” approach. Try half of the outstanding dependencies and if it doesn’t work, cut it in half again.

Good luck and please report if you make any more progress. Maybe this will help someone else someday.

@Borodybits I googled to exclude usage of 64-bit library and found the solution. I used following gradle command in app gradle file’s defaultConfig:

ndk {
abiFilters “armeabi”, “armeabi-v7a”, “x86”, “mips”
}

After this SQLCipher is working on all the devices.

Thanks a lot for you help and guidance.