在 64 位 android 上使用 32 位 jni 库 [英] Use 32-bit jni libraries on 64-bit android

查看:36
本文介绍了在 64 位 android 上使用 32 位 jni 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Nexus 9 上使用本机库运行应用程序.

I've tried running an application using a native library on the Nexus 9.

应用程序退出并显示错误消息:

The application exits with an error message:

java.lang.UnsatisfiedLinkError: dlopen failed: "lib_xyz.so" is 32-bit instead of 64-bit

是否有任何已知的解决方法可以解决此问题(当然,除了重新编译库并使 apk 更大)?

Is there any known workaround for this problem (except, of course, recompiling the library and making the apk bigger)?

推荐答案

找到解释:64 位 Android 可以使用 32 位本机库作为后备,只有在 System.loadlLibrary() 找不到更好的默认搜索路径.如果您使用 System.load() 和完整的库路径强制系统加载 32 位库,则会得到 UnsatisfiedLinkError.所以第一个解决方法是使用 System.loadLibrary() 而不是 System.load().

Found an explanation: 64-bit Android can use 32-bit native libraries as a fallback, only if System.loadlLibrary() can't find anything better in the default search path. You get an UnsatisfiedLinkError if you force the system to load the 32-bit library using System.load() with the full library path. So the first workaround is using System.loadLibrary() instead of System.load().

必须考虑的另一件事是库不能混合:回退行为仅适用于您的应用程序加载的第一个库.如果第一个是 64 位,则同一个应用程序无法加载 32 位库,反之亦然.

An additional thing that has to be taken into account is that libraries cannot be mixed: the fallback behaviour only applies for the first library your application loads. If the first one is 64-bit, no 32-bit libraries can be loaded by the same application, and vice versa.

这篇关于在 64 位 android 上使用 32 位 jni 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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