Android的工作室:的UnsatisfiedLinkError:findLibrary返回null - 加载本地库 [英] Android studio: UnsatisfiedLinkError: findLibrary returned null - loading native library

查看:591
本文介绍了Android的工作室:的UnsatisfiedLinkError:findLibrary返回null - 加载本地库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在采用两个库的Andr​​oid Studio中的一个应用程序。使用Android包装和JAR-库中的本地库。
出于某种原因,如果其他jar库被编译到项目的本地库将不会加载。所以,如果我跑,只有本地库的应用程序,一切工作正常。我添加了其他jar库到我的gradle这个文件,并咚......一个的UnsatisfiedLinkError:

I am making an app in Android Studio which uses two libraries. A native library with an Android wrapper and a jar-library. For some reason, the native library won't load if the other jar-library is compiled into the project. So if I run the app with only the native library, everything works fine. I add the other jar-library to my gradle-file and boom... an 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

我的应用程序运行正常,当我用这个:

My app runs fine when I use this:

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仓库:

or when I try to use the same library but using the Maven repository:

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

或者如果我尝试把在jniLibs文件夹中的jar:

or if I try to place the jar in jniLibs folder:

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

我不知道哪里出了问题的根源所在。随着两个库之一,Android的工作室还是我做错了什么?

I have no idea where the root of the problem lies. With one of the two libraries, Android Studio or am I doing something wrong?

注意:
我知道已经有StackOverflow上关于UnsatisfiedLinkErrors很多问题,但这些都不为我的问题提供解决方案。我没有问题,装载本地库,如果它是我使用的唯一库...

Note: I know there have been many questions on StackOverflow regarding UnsatisfiedLinkErrors, yet none of these provide solutions for my problem. I have no problem loading the native library if it's the only library I use...

推荐答案

我发现这个问题。另一个罐子我想添加内部使用C ++库,可支持 armeabi armeabi-V7A 86 MIPS 。我用这一切的时候,才支持本机库 armeabi

I found the problem. The other jar I wanted to add uses internally a C++ library with support for armeabi, armeabi-v7a, x86 and mips. The native library I was using all this time supported only armeabi.

我使用的测试设备是armeabi-V7A设备。这一切的时候,当我使用本机库,该设备在我的库目录的armeabi-V7A检查库。如果它不能找到它,它会尝试armeabi目录。

The device I am using for testing is a armeabi-v7a device. All this time when I was using the native library, the device checked for the library in the armeabi-v7a of my libs directory. If it couldn't find it there, it would try the armeabi directory.

当我打开另一瓶为4种不同体系结构的支持,设备加载armeabi-V7A库。因为它找到了一个armeabi-V7A库罐子,它会尝试加载本地库相同的架构。如果未找到该库,也不会检查armeabi目录作为备份,因此 findLibrary 返回null,因此的UnsatisfiedLinkError

When I load the other jar with support for 4 different architectures, the device loads the armeabi-v7a library. As it found an armeabi-v7a library for the jar, it will try to load the native library for the same architecture. If the library wasn't found, it will not check the armeabi directory as a backup, so the findLibrary returns null, hence the UnsatisfiedLinkError.

我通过一个目录的armeabi架构和复制armeabi-V7A目录的.so库到它解决了。

I solved it by making a directory for the armeabi architecture and copying the .so-library of the armeabi-v7a directory into it.

这篇关于Android的工作室:的UnsatisfiedLinkError:findLibrary返回null - 加载本地库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆