Android studio: UnsatisfiedLinkError: findLibrary returned null - loading native library

Android studio: UnsatisfiedLinkError: findLibrary returned null - loading native library

我正在 Android Studio 中制作一个使用两个库的应用程序。带有 Android 包装器和 jar 库的本机库。 出于某种原因,如果将其他 jar 库编译到项目中,则不会加载本机库。因此,如果我 运行 只有本机库的应用程序,一切正常。我将另一个 jar-library 添加到我的 gradle-file 和 boom... 一个 UnsatisfiedLinkError:

java.lang.UnsatisfiedLinkError: Couldn't load MobileOcrEngine from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null

我的应用程序运行在我使用这个时很好:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
    compile 'com.android.support:support-v13:21.0.2'
    compile project(':wheel')
}

尝试时出现错误:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
    compile 'com.android.support:support-v13:21.0.2'
    compile project(':wheel')
    compile files('libs/realm-0.78.0.jar')
}

或者当我尝试使用相同的库但使用 Maven 存储库时:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
    compile 'com.android.support:support-v13:21.0.2'
    compile project(':wheel')
    compile 'io.realm:realm-android:0.78.0'
}

或者如果我尝试将 jar 放在 jniLibs 文件夹中:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'src/main/jniLibs')
    compile 'com.android.support:support-v13:21.0.2'
    compile project(':wheel')
}

我不知道问题的根源在哪里。使用两个库之一,Android Studio 还是我做错了什么?

注: 我知道 Whosebug 上有很多关于 UnsatisfiedLinkErrors 的问题,但其中 none 为我的问题提供了解决方案。如果它是我唯一使用的库,我加载本机库没有问题...

我发现了问题。我想添加的另一个 jar 在内部使用 C++ 库,支持 armeabiarmeabi-v7ax86mips。我一直使用的本机库仅支持 armeabi.

我用来测试的设备是armeabi-v7a设备。一直以来,当我使用本机库时,设备都会在我的 libs 目录的 armeabi-v7a 中检查该库。如果在那里找不到它,它将尝试 armeabi 目录。

当我加载另一个支持 4 种不同架构的 jar 时,设备会加载 armeabi-v7a 库。当它找到 jar 的 armeabi-v7a 库时,它将尝试为相同的体系结构加载本机库。如果找不到库,它不会检查 armeabi 目录作为备份,因此 findLibrary returns 为空,因此 UnsatisfiedLinkError.

我通过为armeabi架构创建一个目录并将armeabi-v7a目录的.so-library复制到其中来解决它。

defaultConfig {
    ...

    ndk {
        abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
    }

}