我已经坚持了好几个星期了。
我一直在 Android Torrent 客户端中使用 libtorrent。最近,我想添加新功能,例如磁力链接。
所有本机函数都在 中声明PROJECT_FOLDER/jni/libtorrent.h
和实现PROJECT_FOLDER/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);
但是每当我调用它时,我都会得到UnsatisfiedLinkError: MagnetToTorrent
. 这真的很奇怪,因为我之前添加了原生函数,而且它们运行良好。
很感谢任何形式的帮助。谢谢你。
编辑:所有声明的函数libtorrent.h
都被这样包围extern "C" {}
:
#ifdef __cplusplus
extern "C" {
#endif
/*Function declarations*/
#ifdef __cplusplus
}
#endif