Problem in loading .so file

145 views
Skip to first unread message

JC

unread,
Sep 10, 2010, 8:53:26 AM9/10/10
to android-ndk
Hello All,

I am developing GUI using android 1.5(ndk, sdk(r3)), using JAVA-JNI-C
bridge.

My GUI application can not load my shared object library (.SO) file. I
have gone thru posts but could not find anything working.

followings are my files and findings:

jni\Android.mk -- generates libHellojni.so file
=============
LOCAL_CFLAGS += -g
LOCAL_CFLAGS += -DLINUX
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_MODULE := libHellojni
LOCAL_SRC_FILES := Hellojni.cpp

LOCAL_SHARED_LIBRARIES := libmedia
LOCAL_LDLIBS := -llog -ldl
include $(BUILD_SHARED_LIBRARY)


In eclipse i am able to build successfully.

But when emulator loads my activity, my JAVA class for JNI interface
gives following errors in logcat.

WARN/ActivityManager(574): Activity idle timeout for
HistoryRecord{435eb368 {com.example/com.example.ActivityUIMain}}
WARN/dalvikvm(8156): Exception Ljava/lang/UnsatisfiedLinkError; thrown
during Lcom/example/CCHellojni;.<clinit>
DEBUG/AndroidRuntime(8156): Shutting down VM
WARN/dalvikvm(8156): threadid=3: thread exiting with uncaught
exception (group=0x4000fe70)
ERROR/AndroidRuntime(8156): Uncaught handler: thread main exiting due
to uncaught exception
ERROR/AndroidRuntime(8156): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(8156): at
com.example.ActivityUIMain.onCreate(ActivityUIMain.java:44)
ERROR/AndroidRuntime(8156): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
ERROR/AndroidRuntime(8156): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
ERROR/AndroidRuntime(8156): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
ERROR/AndroidRuntime(8156): at android.app.ActivityThread.access
$1800(ActivityThread.java:112)
ERROR/AndroidRuntime(8156): at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1692)
ERROR/AndroidRuntime(8156): at
android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(8156): at android.os.Looper.loop(Looper.java:
123)
ERROR/AndroidRuntime(8156): at
android.app.ActivityThread.main(ActivityThread.java:3948)
ERROR/AndroidRuntime(8156): at
java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(8156): at
java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(8156): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
ERROR/AndroidRuntime(8156): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
ERROR/AndroidRuntime(8156): at
dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(8156): Caused by: java.lang.UnsatisfiedLinkError:
Library libcfjni not found
ERROR/AndroidRuntime(8156): at
java.lang.Runtime.loadLibrary(Runtime.java:489)
ERROR/AndroidRuntime(8156): at
java.lang.System.loadLibrary(System.java:557)
ERROR/AndroidRuntime(8156): at
com.example.CCHellojni.<clinit>(CHellojni.java:80)


When i m dong

# cd bin/ndk/local/armeabi/; objdump -x libHellojni.so |grep NEEDED
bash: cd: bin/ndk/local/armeabi/: No such file or directory
NEEDED libmedia.so
NEEDED libc.so
NEEDED libstdc++.so
NEEDED libm.so
NEEDED liblog.so
NEEDED libdl.so

Please guide me further...

Thanks in advance.

JC

mic _

unread,
Sep 10, 2010, 10:26:58 AM9/10/10
to andro...@googlegroups.com
I don't know what's causing your unsatisfied linker error, since none of your code was listed. But you're linking against a library (libmedia) that isn't part of the API officially supported by the NDK. This is likely to cause problems for you if you're aiming to run your application on different devices and on different android releases.

/Michael



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Christian Linne

unread,
Sep 10, 2010, 10:48:35 AM9/10/10
to andro...@googlegroups.com
ERROR/AndroidRuntime(8156): Caused by: java.lang.
UnsatisfiedLinkError:
Library libcfjni not found

I'm wondering what you told System.loadLibrary(...) to load - it always has to be onl y the name of the library. Regarding to the quotation, there is something that doesn't fit in that case.
2010/9/10 mic _ <mico...@gmail.com>



--
_________
Mit freundlichen Grüßen
Yours sincerely

Christian Linne

Mail (private): linn...@aol.com
Mail (official): Christi...@googlemail.com,
ICQ: 293253013

David Turner

unread,
Sep 10, 2010, 11:49:32 AM9/10/10
to andro...@googlegroups.com
Are you linking against the system's libmedia.so or you own library by the same name ?

In the first case, this is not surprising at all. In the second, this is more surprising. Did you load it before libHellojni.so through System.loadLibrary() though ?

On Fri, Sep 10, 2010 at 2:53 PM, JC <j...@oriolesoftware.com> wrote:

JC

unread,
Sep 11, 2010, 12:48:15 AM9/11/10
to android-ndk
Hello All,

Thanks a lot.

David
libmedia.so is from system's.

in Java code i am doing following:

System.loadLibrary("Hellojni");

I have tried following also

System.loadLibrary("media");
System.loadLibrary("Hellojni");

which gave me error saying could not find libmedia.

I havent tried loading media after my Hellojni.


Christian Linne
Please read as follows:
>>> ERROR/AndroidRuntime(8156): Caused by: java.lang.
>>> UnsatisfiedLinkError:
>>> Library libHellojni not found

Should it be Hellojni there, is what you are thinking?


Michael
In android.mk I am linking media library.

I have also tried to do following which build my libHellojni.so
successfully but failed in loadlibrary in JAVA.
#LOCAL_SHARED_LIBRARIES := libmedia
LOCAL_LDLIBS := -llog -ldl -media


Please guide me further.

Thanks,
JC
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

Chris Stratton

unread,
Sep 11, 2010, 1:39:51 AM9/11/10
to android-ndk
I would grep -R cfjni your entire collection of android related disk
storage - and the lib directory of the device. There isn't a monkey in
the handset dispatching calls to dlopen() on random strings, that has
to be coming from somewhere...

Christian Linne

unread,
Sep 11, 2010, 8:32:44 AM9/11/10
to andro...@googlegroups.com
>>> ERROR/AndroidRuntime(8156): Caused by: java.lang.
>>> UnsatisfiedLinkError:
>>> Library libHellojni not found

Should it be Hellojni there, is what you are thinking?
I was just wondering why the loader complains about a library that does not seems to be yours. I don't even know what libcfjni is, haven't seen that yet.

System.loadLibrary("media");
I don't think this will ever work, because in the Android case, loadLibrary will only check the application's directory, and libmedia is from the system's one.

 
LOCAL_LDLIBS := -llog -ldl -media
There is a missing "l" before "media". But, you should avoid linking against parts of the private API.
 
2010/9/11 Chris Stratton <cs0...@gmail.com>
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Chris Stratton

unread,
Sep 11, 2010, 10:36:38 AM9/11/10
to android-ndk
Unlike loadlibrary, just plain system.load() can take an absolute
path.

Private apis are a separate issue.
> > > > > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > <android-ndk%2Bunsubscribe@googlegr oups.com>
> > > > > .
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/android-ndk?hl=en.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> > http://groups.google.com/group/android-ndk?hl=en.
> >
> >
>
>
> --

David Turner

unread,
Sep 13, 2010, 5:50:16 AM9/13/10
to andro...@googlegroups.com
On Sat, Sep 11, 2010 at 6:48 AM, JC <j...@oriolesoftware.com> wrote:
Hello All,

Thanks a lot.

David
  libmedia.so is from system's.


Then it's probably not surprising. libmedia.so is a highly volatile part of the system and will continue to do so.
I guess you tried to access a part of the ABI that changed between platform releases, and the dynamic link
doesn't work anymore because your code is trying to find a symbol that is not in the system's version of the
library anymore.

Another case of "don't link against system libraries, or you'll regret it !", I guess ....
 
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages