的UnsatisfiedLinkError的Andr​​oid [英] UnsatisfiedLinkError Android

查看:156
本文介绍了的UnsatisfiedLinkError的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有这样的应用程序加载本机库,而这个库提供 本机方法为我们打电话。在某些手机(特别是慢 的),这将导致的问题。一个的UnsatisfiedLinkError发生时 (我认为)图书馆还是被装和一个方法被调用 prematurely。

We have this app that loads native library, and this library provides native methods for us to call. On some phones (particularly the slower ones), this causes a problem. An UnsatisfiedLinkError occurs whenever (I think) the library is still being "loaded" and a method is called prematurely.

有没有办法来处理这​​个问题呢?就像如果已经被加载了库检查。

Is there a way to handle this issue? Like checking if a library is already loaded.

推荐答案

即使在较慢的设备,调用的System.loadLibrary()是非常快的;但如果你的应用程序运行多线程,或者如果涉及静态构造函数的类仅在回应一些UI事件时加载的 - 那么有可能是一个竞争条件:即依靠本地库是present会造成一些其他类崩溃。

Even on slower devices, the call to System.loadLibrary() is very fast; but if your app runs multithreaded, or if the class that involves the static constructor is only loaded in response to some UI event - then there could be a race condition: some other classes that rely on the native library being present will cause a crash.

没有禁止使用静态构造函数调用其中的的System.loadLibrary()为具有本地方法的所有类。你可以看到本机库的一些警告加载乘法,但是这并没有产生消极后果。

There is no prohibition of using the static constructor which calls System.loadLibrary() for all classes that have native methods. You could see some warnings about native library being loaded multiply, but this does not have negative consequences.

有时候,我们使用自定义的Java code提取机库的当应用程序运行,而不是依赖于系统安装的第一次,文件目录,这使他们进入<一href="http://developer.android.com/reference/android/content/pm/ApplicationInfo.html#nativeLibraryDir"相对=nofollow> LIB 目录。这应该格外小心进行,并且所有的活动的(双关语意)应该等到提取库(通常来自APK的资产文件夹)中就完成了。

Sometimes, we use custom Java code to extract the native libraries to files directory when the app is run for the first time, instead of relying on the system installer, which puts them into the lib directory. This should be done with extra care, and all activity (pun intended) should wait until extraction of the libs (typically from the assets folder of APK) is complete.

另一个捕获可能是针对某些设备,可以使用系统库库的名称。在这种情况下,的System.loadLibrary()将加载库从 /系统/ lib目录并没有从您的应用程序;但是这难以解释的3秒延时的​​效果。

Another catch could be that for some devices, the name of your library may be used by a system library. In such case, System.loadLibrary() will load the library from /system/lib and not from your app; but this can hardly explain the effect of 3 sec delay.

这篇关于的UnsatisfiedLinkError的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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