的UnsatisfiedLinkError在Android 5.0棒棒糖棒棒糖、UnsatisfiedLinkError、Android

2023-09-08 09:56:38 作者:菊花也是花

我通过加载我的本机库:

I am loading my native library by:

try {
       System.loadLibrary("myNative");
} catch (UnsatisfiedLinkError e) {
       //java.lang.UnsatisfiedLinkError here
       System.load("/data/data/com.my.app/my_native/libmyNative.so");
}

以上code正常工作中的其他设备,除了安卓5.0棒棒糖。当运行的Andr​​oid 5.0棒棒堂设备,我不断收到以下错误:

The above code works fine on other devices except Android 5.0 Lollipop. When run on Android 5.0 Lollipop device, I constantly get the following error:

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.my.app/my_native/libmyNative.so" is 32-bit instead of 64-bit
at java.lang.Runtime.load(Runtime.java:331)
at java.lang.System.load(System.java:982)

如何解决这个问题呢?

How to solve this problem?

===更新====

=== UPDATE ====

我复制了机库,从的lib /< archType> /libmyNative.so /data/data/com.my.app/ my_native / libmyNative.so ,然后用上面的code加载库。

I copied the native library from lib/<archType>/libmyNative.so to /data/data/com.my.app/my_native/libmyNative.so and then use the above code to load the library.

推荐答案

如此看来,打包库(从的lib /&LT复制它们的方式某些部分; archType&GT; /libmyNative.so /data/data/com.my.app/my_native/libmyNative.so )混淆了安装程序。当安装APK,它应该已经自动地提取正确的弓型的图书馆,让他们提供给的System.loadLibrary - 你不应该需要手动复制到任何一个如 my_native 自定义目录。

It seems that some part of the way of packaging your libs (copying them from lib/<archType>/libmyNative.so to /data/data/com.my.app/my_native/libmyNative.so) confuses the installer. When installing an APK, it should already automatically extract the libraries of the right arch type and have them available to System.loadLibrary - you shouldn't need to copy anything manually into a custom directory like my_native.

&LT; archType&GT; 在这种情况下,现有的(armeabi , 之一armeabi-V7A 等),或你想要的名称吗?如果不是标准之一,此安装程序将不知道你的应用程序包含32位本机code,因此将启动应用程序的进程在preferred模式(64位)。

Is <archType> in this case one of the existing (armeabi, armeabi-v7a, etc) or something of your own? If it isn't one of the standard ones, the installer won't know that your app contains 32 bit native code, and thus will launch your app's process in the preferred mode (64 bit).