使用SQLCipher和Crashlytics for x86_64和arm84_v8a时,Android应用程序崩溃与UnsatisfiedLinkError

时间:2016-11-18 09:55:08

标签: android crashlytics sqlcipher unsatisfiedlinkerror

我创建了一个非常小的应用程序,只显示“Hello World”。 主要活动调用加载SQLCipher库。

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
    }
}


build.gradle(module:app)是:

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'
}


这个应用程序按预期工作 但是,当我将Crashlytics添加到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'
}

一旦启动,应用程序崩溃并出现错误“java.lang.UnsatisfiedLinkError ...找不到”libsqlcipher.so“ - 我甚至没有从我的活动中调用Crashlytics。

                  --------- 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)

这仅适用于x86_64和arm64_v8a ABI。在后一种情况下,错误列表包含“arm64_v8a”而不是“x86_64”

知道出了什么问题吗? 提前谢谢,
格哈德

2 个答案:

答案 0 :(得分:9)

自己找到答案。

SQLCipher显然不支持64位架构 所以在build.gradle中我添加了一个abiFilter语句来排除64位架构:

...
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25

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

不再崩溃了!

答案 1 :(得分:2)

您还应该删除mips;适用于Android的SQLCipher目前仅包含armeabiarmeabi-v7ax86的原生图书馆。