java.lang.UnsatisfiedLinkError中在安卓5.0加载本机库时, [英] java.lang.UnsatisfiedLinkError when loading native library in Android 5.0

查看:2640
本文介绍了java.lang.UnsatisfiedLinkError中在安卓5.0加载本机库时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过加载我的本机库:

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/app_native/libmyNative.so");
}

以上code为最后包装到一个JAR文件。

The above code is finally packaged to a Jar file.

在另一个项目中,我加载上述罐 DexClassLoader

In another project, I load the above Jar with DexClassLoader:

DexClassLoader dexClassLoader = new DexClassLoader(jarPath,
                    optJarPath,
                    getDir("native", Context.MODE_PRIVATE),
                    getClassLoader());

请注意,构建这个 dexClassLoader 实例时,我已经指定了路径其中本地code的位置,这是 GETDIR(原生,Context.MODE_PRIVATE)

Notice that when constructing this dexClassLoader instance, I have specified the path where the native code is located, that's getDir("native", Context.MODE_PRIVATE).

(我使用 NDK的发布10 产生机库当本地code文件中的 libmyNative.so 生成,我的Java code(其打包到最终罐)检查CPU体系结构类型和放大器;复制权之一 GETDIR(原生,Context.MODE_PRIVATE)

(I am using NDK release 10 to generate the native library. When the native code file libmyNative.so is generated, my java code (which packaged to final Jar) checks the CPU architecture type & copy the right one to getDir("native", Context.MODE_PRIVATE).)

以上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/app_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?

推荐答案

您似乎在尝试使用32位库在64位的目标。如果你不能提供一个64位的一个,你必须说服的Andr​​oid回退到32位模式,以适应图书馆。

You appear to be attempting to use a 32-bit library on a 64-bit target. If you can't provide a 64-bit one, you will have to convince Android to fallback to 32-bit mode to accommodate the library.

显然,兼容模式(源似乎称其为ABI覆盖)通常被设置在安装时,安装程​​序发现,只有32位(而不是64位)库可用。但在你的情况,该库是不可见的,在安装时,这样是行不通的。

Apparently, compatibility mode (the source seems to call it an ABI override) is normally set at install time, by the installer discovering that only 32-bit (and not 64-bit) libraries are available. But in your case, the library is not visible at install time, so that won't work.

如果你把一个虚拟的32位LIB的APK是最匹配的64位器件的需求,那么系统将有望配置您的应用程序在32位兼容模式运行,这样以后装你真正的32位LIB将实际工作。

If you place a "dummy" 32-bit lib in the apk that is the closest match for the 64-bit device's needs, then the system will hopefully configure your app to run in 32-bit compatibility mode so that later loading your real 32-bit lib will actually work.

我不知道,如果32位LIB将需要一个真正的对与正确的位置和合理名的空文件,但HELLO-JNI项目从NDK样本文件夹的libhello-jni.so应该应该工作。您不需要任何相应的Java code,正好有个本地库的安装程序可以发现(但是,要求把它作为一个测试可能不是一个坏主意)。

I don't know if the 32-bit lib would need to be a real one vs. an empty file with the correct location and plausible name, but the hello-jni project from the ndk samples folder's libhello-jni.so should should work. You won't need any corresponding java code, just to have a native library the installer can discover (however, calling into it as a test might not be a bad idea).

有可能的有可能是一些其他的方式(多个)触发此,如一些在所述清单(虽然没有什么是所提到的文件中)。我想不太可能怀疑,在运行时的任何措施将工作,因为这种模式可能已经被牢牢地之前,你的任何code运行时的设置(它看起来像你实际上可能结束了对此类受精卵运行的两个实例一个系统中,一个64位,而另一个32,与这个想法是,应用程序获得由哪一个被认为是适当的)发射。

It is possible there may be some other way(s) to trigger this, such as something in the manifest (though nothing is mentioned in the documentation). I'd be less likely to suspect that any measures at runtime will work, since this mode may already be firmly set before any of your code runs (it looks like you may actually end up with two instances of zygote running on such a system, one 64 bit and the other 32, with the idea being that apps get launched by whichever one is believed to be appropriate).

这篇关于java.lang.UnsatisfiedLinkError中在安卓5.0加载本机库时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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