Question

I have a working Android app that uses the armeabi libraries for SQLCipher but I cannot make the app work for x86.

When I try and debug the app on an x86 device I can step through the app until the call to SQLiteDatabase.loadLibs(this); which results in A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)

I've checked the library loading in logcat;

armeabi

D/dalvikvm? Trying to load lib /data/data/com.eglootech.sqlcipher/lib/libstlport_shared.so 0x42562c10
D/dalvikvm? Added shared lib /data/data/com.eglootech.sqlcipher/lib/libstlport_shared.so 0x42562c10
D/dalvikvm? No JNI_OnLoad found in /data/data/com.eglootech.sqlcipher/lib/libstlport_shared.so 0x42562c10, skipping init
D/dalvikvm? Trying to load lib /data/data/com.eglootech.sqlcipher/lib/libsqlcipher_android.so 0x42562c10
D/dalvikvm? Added shared lib /data/data/com.eglootech.sqlcipher/lib/libsqlcipher_android.so 0x42562c10
D/dalvikvm? No JNI_OnLoad found in /data/data/com.eglootech.sqlcipher/lib/libsqlcipher_android.so 0x42562c10, skipping init
D/dalvikvm? Trying to load lib /data/data/com.eglootech.sqlcipher/lib/libdatabase_sqlcipher.so 0x42562c10
D/dalvikvm? Added shared lib /data/data/com.eglootech.sqlcipher/lib/libdatabase_sqlcipher.so 0x42562c10
I/Database? JNI_OnLoad called
I/Database? JNI_OnLoad register methods

x86

D/dalvikvm? Trying to load lib /data/app-lib/com.eglootech.electorlookup-2/libstlport_shared.so 0x41c3e430
D/dalvikvm? Added shared lib /data/app-lib/com.eglootech.electorlookup-2/libstlport_shared.so 0x41c3e430
D/dalvikvm? No JNI_OnLoad found in /data/app-lib/com.eglootech.electorlookup-2/libstlport_shared.so 0x41c3e430, skipping init
D/dalvikvm? Trying to load lib /data/app-lib/com.eglootech.electorlookup-2/libsqlcipher_android.so 0x41c3e430
D/dalvikvm? Added shared lib /data/app-lib/com.eglootech.electorlookup-2/libsqlcipher_android.so 0x41c3e430
D/dalvikvm? No JNI_OnLoad found in /data/app-lib/com.eglootech.electorlookup-2/libsqlcipher_android.so 0x41c3e430, skipping init
D/dalvikvm? Trying to load lib /data/app-lib/com.eglootech.electorlookup-2/libdatabase_sqlcipher.so 0x41c3e430
D/dalvikvm? Added shared lib /data/app-lib/com.eglootech.electorlookup-2/libdatabase_sqlcipher.so 0x41c3e430
A/libc? Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2313 (h.electorlookup)

Why would the JNI_OnLoad calls be missing?

I can step into the I can step into the the call to the SQLiteDatabase.loadLibs(this); and the error comes from SQLiteDatabase and the call to loadLibs(android.content.Context context, java.io.File workingDir) where workingDir is /data/data/com.eglootech.sqlcipher/files.

I have included both the armeabi and x86 native libraries in the same way within my Android Studio project;

libs folder with armeabi and x86

These are the binaries you download from SQLCipher and then each platform directory is zipped under a lib folder and then the zip renamed to .jar. They appear in the list as lib.armeabi and lib.x86 although they are nested folders within the .jar.

Then in Gradle I have the following that should make sure the native files are copied across;

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

Is there a reason the native libraries would not be included for x86?

I have also tried including the libraries not in a .jar and just in a directory according to; Android studio, gradle and NDK

Again the app works in armeabi but not x86.

The app can work on x86 with just the armeabi libraries but the performance suffers because of the virtualisation and we want to prove with the correct native libraries x86 performs as well if not better.

Was it helpful?

Solution

The original problem was due to the structure of the .jar folder and it not locating the correct native library. The native libraries needed to be in a single .jar file.

The latest version of SQLCipher for Android is distributed via an AAR package, integration within Gradle can be performed by adding the following to the app/build.gradle file:

repositories {
    mavenCentral()
}

dependencies {
    compile 'net.zetetic:android-database-sqlcipher:3.5.7@aar'
    compile fileTree(include: '*.jar', dir: 'libs')
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top