Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用本机库时出现Android UnsatifiedLink错误_Android_Java Native Interface_Unsatisfiedlinkerror - Fatal编程技术网

使用本机库时出现Android UnsatifiedLink错误

使用本机库时出现Android UnsatifiedLink错误,android,java-native-interface,unsatisfiedlinkerror,Android,Java Native Interface,Unsatisfiedlinkerror,我已经被困在这几个星期了 我一直在Android torrent客户端中使用libtorrent。最近,我想添加一些新功能,比如磁铁链接 所有本机函数都在PROJECT\u文件夹/jni/libtorrent.h中声明,并在PROJECT\u文件夹/jni/libtorrent.cpp中实现 到目前为止,没有出现任何问题,但最近,我在libtorrent.h中添加了这个新函数: JNIEXPORT jstring JNICALL Java_com_my_package_LibTorrent_Ma

我已经被困在这几个星期了

我一直在Android torrent客户端中使用libtorrent。最近,我想添加一些新功能,比如磁铁链接

所有本机函数都在
PROJECT\u文件夹/jni/libtorrent.h
中声明,并在
PROJECT\u文件夹/jni/libtorrent.cpp
中实现

到目前为止,没有出现任何问题,但最近,我在
libtorrent.h
中添加了这个新函数:

JNIEXPORT jstring JNICALL Java_com_my_package_LibTorrent_MagnetToTorrent
(JNIEnv *env, jobject obj, jstring MagnetLink, jstring TorrentFolder);
我在
libtorrent.cpp

JNIEXPORT jstring JNICALL Java_com_my_package_LibTorrent_MagnetToTorrent
(JNIEnv *env, jobject obj, jstring MagnetLink, jstring TorrentFolder) {
        //function code here
}
我在代码上运行了
ndk build
,并编译了它

com.my.package.LibTorrent
类中,我添加了以下声明,与之前声明其他本机方法的方式相同,效果很好:

public native String MagnetToTorrent(String MagnetLink, String TorrentFolder);
但每当我调用它时,就会得到
不满意的linkerror:MagnetToTorrent
。这真的很奇怪,因为我以前添加了本机函数,它们工作得很好

非常感谢您的帮助。多谢各位

编辑:在
libtorrent.h
中声明的所有函数都被
extern“C”{}
包围,如下所示:

#ifdef __cplusplus
extern "C" {
#endif
/*Function declarations*/
#ifdef __cplusplus
}
#endif

您是否有可能忘记了外部“C”?

我看到的唯一原因是您的本机库没有符号。自从上次库更改(您声称对您有效)以来,您是否碰巧更改了构建路径和/或构建的其他方面?“较新”的库不是在Java构建不知道的其他地方构建的吗?找到库文件(.so?),并检查它是否有导出的符号(dumpbin、objdump、nm,因平台而异)。确保它确实是您的Java构建加载的一个库。

我终于找到了问题所在。我不得不将这一行添加到
jni/Application.mk

APP_ABI := armeabi armeabi-v7a
这使得本机代码也为ARMv7处理器构建,这就是我在新手机上所拥有的


所有其他答案对于其他有类似问题的开发人员也应该有用。我为他们每个人都打了+1。对于可能导致应用程序抛出
不满意链接错误的其他问题,此链接可能会有所帮助:

请在.h和.h中对完整程序包名称Java\u com\u my\u package\u LibTorrent\u magnettorrent进行三次拼写检查。cpp@AndrewG谢谢,但是我已经检查过很多次了,我数不清了。我想我现在应该已经看到了,所以我怀疑情况是否如此