[英]Native library in android project not found (UnsatisfiedLinkError)
I have an android project and I added an external .jar file which contains several .class files and in addition some .so files.我有一个 android 项目,我添加了一个外部 .jar 文件,其中包含几个.class文件和一些.so文件。
When I try to use some methods which are provided by the .class files I get a UnsatisfiedLinkError-Exception which says that the implementation for those methods couldn't be found.当我尝试使用.class文件提供的一些方法时,我得到一个 UnsatisfiedLinkError-Exception,它表示找不到这些方法的实现。
Obviously the problem is that the .so libraries which contain the implementation were not correctly loaded/cannot be found.显然问题是包含实现的.so库没有正确加载/无法找到。
What do I have to do that the native libraries in the external .jar file can be found from the runtime?我该怎么做才能从运行时找到外部.jar文件中的本机库?
More details:更多细节:
I'm using AndroidStudio and the app is tested on the emulator with the device "Nexus 5 API 23 x86".我正在使用 AndroidStudio,并且该应用程序已在带有设备“Nexus 5 API 23 x86”的模拟器上进行了测试。 The .so files support x86 too.
.so文件也支持 x86。
I copied the .jar file into the /app/libs folder.我将.jar文件复制到/app/libs文件夹中。 Then I right-clicked the file in the IDE and selected "Add as library".
然后我在 IDE 中右键单击该文件并选择“添加为库”。
As you see that crash is saying that it could not load native library.如您所见,崩溃是说它无法加载本机库。 But why?
但为什么?
First of all I checked my structure, If native library .so files located correctly.首先,我检查了我的结构,如果本机库 .so 文件位置正确。
Seems everything was okay except this crazy error.除了这个疯狂的错误,似乎一切都好。
Then after some research, I find out that some of android devices has 64-bit processors.然后经过一番研究,我发现一些 android 设备具有 64 位处理器。
This devices generates and check arm64 folder to load native library.该设备生成并检查 arm64 文件夹以加载本机库。 That was the problem.
那就是问题所在。 Because my project does not have arm64 folder.
因为我的项目没有 arm64 文件夹。
Here is the solution;这是解决方案;
defaultConfig{
ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.