使用64位的android 32位JNI库

使用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位的Andr​​oid可以使用32位本机库作为备用,只有当System.loadlLibrary()找不到什么更好的默认的搜索路径。 你得到的UnsatisfiedLinkError如果强制系统加载使用System.load()与全库路径的32位库。 因此,第一个解决方法是使用的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.