Android NDK 偶尔出现 UnsatisfiedLinkError
我正在寻找线索,解释为什么我的 Android 应用程序偶尔会在特定 ndk 调用上引发 UnsatisfiedlinkError 异常:
我有一个通过 ndk 加载一个本机库的 Android 应用程序。
本机库是用 C++ 编写的并使用 STL(在我的 makefile 中我设置了 APP_STL := stlport_static)。不使用或不需要其他库。本机库拥有大约 20 个 Java 类的大约 300 个本机方法。
大多数时候一切都很好。但我的用户时不时会遇到 UnsatisfiedLinkError 异常。异常总是在相同的本机函数调用的同一位置触发,但奇怪的是,它甚至不是对本机函数的第一次调用,甚至不是对该特定本机函数的第一次调用。
任何线索都欢迎为什么一个特定的本机调用可能失败。 ndk 容易损坏吗?遇到这样的问题怎么调试呢?
具有相同调用的简单测试程序工作得很好。不过,这里是源代码的某些部分:
这是 Java 中的问题 ndk 函数:
public class Server {
...
static private native long longObserveError( );
...
}
这是头文件: 外部“C”{ ...
JNIEXPORT jlong JNICALL Java_be_gentgo_tetsuki_Server_longObserveError
(JNIEnv *, jclass);
...
}
这是实现:
IGSProtocol *server = 0; // initialized later...
JNIEXPORT jlong JNICALL Java_be_gentgo_tetsuki_Server_longObserveError
(JNIEnv *env, jclass)
{
Messenger &mess = server->ObserveError( );
return (long)(&mess);
}
I'm looking for clues why my Android app sporadically throws an UnsatisfiedlinkError exception on a specific ndk call:
I have an Android app that loads one native library through ndk.
The native library is written in C++ and uses STL (in my makefile I have set APP_STL := stlport_static). No other libraries are used or required. The native library has about 300 native methods for about 20 java classes.
All works fine, most of the time. But every now and then my users get an UnsatisfiedLinkError exception. The exception is always triggered at the same spot with the same native function call, but strangely enough it is not even the first call to a native function, not even the first call to that specific native function.
Any clue would be welcome why one specific native call could fails. Can ndk easily be corrupted? How do you debug for such a problem?
Simple test programs with the same call work just fine. Nevertheless here's some parts of the source code:
Here's the problem ndk function in Java:
public class Server {
...
static private native long longObserveError( );
...
}
Here's the header file:
extern "C" {
...
JNIEXPORT jlong JNICALL Java_be_gentgo_tetsuki_Server_longObserveError
(JNIEnv *, jclass);
...
}
And here's the implementation:
IGSProtocol *server = 0; // initialized later...
JNIEXPORT jlong JNICALL Java_be_gentgo_tetsuki_Server_longObserveError
(JNIEnv *env, jclass)
{
Messenger &mess = server->ObserveError( );
return (long)(&mess);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的库文件的名称是什么?我遇到了另一篇 SO 帖子(https://stackoverflow.com/a/18024816),其中那个人的库名称是与仅存在于某些设备上的系统库冲突。重命名他的库解决了这个问题。
What is the name of your library file? I came across another SO post (https://stackoverflow.com/a/18024816) where the guy had a library name that was conflicting with a system library that was only present on some devices. Renaming his library fixed the problem.