Android App crashes with UnsatisfiedLinkError when using SQLCipher and Crashlytics for x86_64 and arm84_v8a
Asked Answered
P

2

6

I created a very minimal application, just showing "Hello World". The main activity makes a call to load the SQLCipher libraries.

package companydomain.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import net.sqlcipher.database.SQLiteDatabase;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SQLiteDatabase.loadLibs(this);            // loading the SQLCipher libraries
    }
}


The build.gradle (module: app) is:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
    }
    return void
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}


This app works as intended.
However, when I add Crashlytics to the build.gradle:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
    }
    return void
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'

    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.5@aar') {
        transitive = true;
    }
}

crashlytics {
    enableNdk true
    androidNdkOut 'src/main/obj'
    androidNdkLibsOut 'src/main/libs'
}


upon start the app crashes with an error "java.lang.UnsatisfiedLinkError ... couldn't find "libsqlcipher.so" - I don't even make a call to Crashlytics from my activity.

                  --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
              Process: companydomain.myapplication, PID: 2887
              java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/companydomain.myapplication-2/base.apk"],nativeLibraryDirectories=[/data/app/companydomain.myapplication-2/lib/x86_64, /vendor/lib64, /system/lib64]]] couldn't find "libsqlcipher.so"
                  at java.lang.Runtime.loadLibrary(Runtime.java:366)
                  at java.lang.System.loadLibrary(System.java:989)
                  at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:196)
                  at net.sqlcipher.database.SQLiteDatabase.loadLibs(SQLiteDatabase.java:189)
                  at companydomain.myapplication.MainActivity.onCreate(MainActivity.java:21)
                  at android.app.Activity.performCreate(Activity.java:5937)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                  at android.app.ActivityThread.access$800(ActivityThread.java:144)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5221)
                  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:899)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)


This happens only for x86_64 and arm64_v8a ABIs. In the latter case the error list contains "arm64_v8a" instead of "x86_64"

Any idea what is wrong?
Thanks in advance,
Gerhard

Predominance answered 18/11, 2016 at 9:55 Comment(0)
P
14

Found the answer by myself.

SQLCipher obviously do not support 64-bit architecture.
So in the build.gradle I added an abiFilter-statement to exclude 64-bit architectures:

...
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25

        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
    return void
}
....


No crashes anymore!

Predominance answered 18/11, 2016 at 11:7 Comment(0)
E
3

You should also remove mips; SQLCipher for Android only includes native libraries for armeabi, armeabi-v7a, and x86 currently.

Eth answered 18/11, 2016 at 14:5 Comment(5)
Hello Nick, a project I inherited is using 4.1.3 version of the SQLCipher library, but I want to confirm if this issue has been fixed in 4.2.0? And I don't have to add this abiFilters? Cos the error just popped up for a user on Android 5.1. Thank you in advance!Strap
@Strap SQLCipher for Android does not include support for mips.Eth
Thank you so much for the reply Nick!Strap
Maybe a stupid question by me: Does it mean that if I exclude an architecture that the ciphers will not be applied on that architectures? Accordingly, no encryption is performed?Foretell
@kuzdu, that depends. For example, on a 64-bit ARM device, if only the 32-bit native ARM variant is present the JVM will load that library. Generally though, if the entire native ABI target is missing, you will likely get load library-based exception.Eth

© 2022 - 2024 — McMap. All rights reserved.