Reputation: 2054
I have been stuck on this for weeks already.
I have been using libtorrent in an Android torrent client. Recently, I wanted to add new features, such as magnet links.
All native functions are declared in PROJECT_FOLDER/jni/libtorrent.h
and implemented in PROJECT_FOLDER/jni/libtorrent.cpp
.
So far, nothing went wrong, but recently, I added this new function in libtorrent.h
:
JNIEXPORT jstring JNICALL Java_com_my_package_LibTorrent_MagnetToTorrent
(JNIEnv *env, jobject obj, jstring MagnetLink, jstring TorrentFolder);
I added its implementation in libtorrent.cpp
JNIEXPORT jstring JNICALL Java_com_my_package_LibTorrent_MagnetToTorrent
(JNIEnv *env, jobject obj, jstring MagnetLink, jstring TorrentFolder) {
//function code here
}
I ran ndk-build
on the code, and it compiled.
In com.my.package.LibTorrent
class, I added the following declaration, same way that I had previously declared other native methods, which worked fine:
public native String MagnetToTorrent(String MagnetLink, String TorrentFolder);
But whenever I call it, I get UnsatisfiedLinkError: MagnetToTorrent
. This is really weird, since I added native functions before, and they worked fine.
Any help is very much appreciated. Thank you.
EDIT: All the functions declared in libtorrent.h
are surrounded with extern "C" {}
like this:
#ifdef __cplusplus
extern "C" {
#endif
/*Function declarations*/
#ifdef __cplusplus
}
#endif
Upvotes: 1
Views: 740
Reputation: 2054
I finally figured out what was wrong. I had to add this line to jni/Application.mk
:
APP_ABI := armeabi armeabi-v7a
This causes the native code to be also built for ARMv7 processors, which is what I have on my new phone.
All the other answers should also be useful for other developers with similar problems. I marked +1 for each of them. For other issues that might cause the app to throw UnsatisfiedLinkError
, this link might be helpful: http://developer.android.com/guide/practices/jni.html#faq_ULE
Upvotes: 0
Reputation: 7293
The only reason i see is that your native library does NOT have the symbol. Since the last library change (which you claim worked for you), haven't you by chance changed build paths and/or other aspects of the build? Isn't the "newer" library being built in some other place which your Java build doesn't know about? Locate your library file (.so?) and inspect it for exported symbols (dumpbin,objdump,nm, varies per platform). Make sure that it is really the one library which your Java build is loading.
Upvotes: 1