How to use a pre-built library in android application

1,036 views
Skip to first unread message

nissar ka

unread,
Jan 14, 2011, 2:24:06 AM1/14/11
to android-ndk
Hi,
I have to build an application which uses some existing native
libraries(libMyTestNCL.so) and the source code of those are not
available.
So i copied the native libraries to ~/jni and created Android.mak
file as follows

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libMyTestNCL-prebuilt
LOCAL_SRC_FILES := libMyTestNCL.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)


****************(I don't want to change the librray name since it has
many dependancies)

Using ndk-build i could place the resultant library in ~/libs/armeabi/
folder.

But while running the application it terminates unespectedly when it's
calling a native method(add()).


Please see the log


01-14 12:24:53.844: INFO/System.out(31940): Static block
01-14 12:24:53.854: DEBUG/dalvikvm(31940): Trying to load lib /data/
data/com.eg.ncd/lib/libMyTestNCL.so 0x432830d8
01-14 12:24:54.304: DEBUG/vending(299): [92]
LocalAssetCache.updateOnePackage(): No local info for com.eg.ncd
01-14 12:24:54.994: DEBUG/dalvikvm(31940): Added shared lib /data/data/
com.eg.ncd/lib/libMyTestNCL.so 0x432830d8
01-14 12:24:54.994: DEBUG/dalvikvm(31940): No JNI_OnLoad found in /
data/data/com.eg.ncd/lib/libMyTestNCL.so 0x432830d8
01-14 12:24:54.994: INFO/System.out(31940): Constructor
01-14 12:24:57.894: INFO/ActivityManager(75): Displayed activity
com.eg.ncd/.sample: 4382 ms (total 4382 ms)
01-14 12:25:01.844: DEBUG/dalvikvm(31940): +++ not scanning '/system/
lib/libwebcore.so' for 'add' (wrong CL)
01-14 12:25:01.844: DEBUG/dalvikvm(31940): +++ not scanning '/system/
lib/libexif.so' for 'add' (wrong CL)
01-14 12:25:01.844: DEBUG/dalvikvm(31940): +++ not scanning '/system/
lib/libFFTEm.so' for 'add' (wrong CL)
01-14 12:25:01.844: DEBUG/dalvikvm(31940): +++ not scanning '/system/
lib/libmedia_jni.so' for 'add' (wrong CL)
01-14 12:25:01.844: DEBUG/dalvikvm(31940): +++ not scanning '/system/
lib/libsrec_jni.so' for 'add' (wrong CL)
01-14 12:25:01.854: WARN/dalvikvm(31940): No implementation found for
native Lcom/eg/ncd/NativeLib;.add (II)I
01-14 12:25:01.854: DEBUG/AndroidRuntime(31940): Shutting down VM
01-14 12:25:01.864: WARN/dalvikvm(31940): threadid=3: thread exiting
with uncaught exception (group=0x4001da28)
01-14 12:25:01.864: ERROR/AndroidRuntime(31940): Uncaught handler:
thread main exiting due to uncaught exception
01-14 12:25:02.064: ERROR/AndroidRuntime(31940):
java.lang.IllegalStateException: Could not execute method of the
activity
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.View$1.onClick(View.java:2027)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.View.performClick(View.java:2344)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.View.onTouchEvent(View.java:4133)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.widget.TextView.onTouchEvent(TextView.java:6504)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.View.dispatchTouchEvent(View.java:3672)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
1202)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.app.Activity.dispatchTouchEvent(Activity.java:1987)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.os.Looper.loop(Looper.java:123)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.app.ActivityThread.main(ActivityThread.java:4203)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
java.lang.reflect.Method.invokeNative(Native Method)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
java.lang.reflect.Method.invoke(Method.java:521)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
dalvik.system.NativeStart.main(Native Method)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): Caused by:
java.lang.reflect.InvocationTargetException
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.eg.ncd.sample.add(sample.java:54)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
java.lang.reflect.Method.invokeNative(Native Method)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
java.lang.reflect.Method.invoke(Method.java:521)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
android.view.View$1.onClick(View.java:2022)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): ... 21 more
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): Caused by:
java.lang.UnsatisfiedLinkError: add
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): at
com.eg.ncd.NativeLib.add(Native Method)
01-14 12:25:02.064: ERROR/AndroidRuntime(31940): ... 25 more

Is there any problem in the way i builded the application?
Anybody please explain me how to build the application properly using
pre-built librraies.

alan

unread,
Jan 14, 2011, 10:04:25 AM1/14/11
to andro...@googlegroups.com
you cannot use prebuilt shared libraries that were not built for android. the
+++ not scanning '/system/ lib/libwebcore.so' for 'add' (wrong CL)
messages are indicating that the libraries are not android libraries

nissar ka

unread,
Jan 16, 2011, 10:55:02 PM1/16/11
to android-ndk
These libraries are made using android-ndk only.
Is android ndk required for it?
I'm using eclipse for building the application and no other tools.
If i copy the librraies directly to ~/libs/armeabi/ will it work? If
yes where i've to refer the librray to application.

If it's not possible could you please explain the simplest procedure
to use pre-built android libraries?

raj gehlot

unread,
Jan 16, 2011, 11:39:41 PM1/16/11
to andro...@googlegroups.com
hi
 how are you
 
i am raj , first u required the cygwin than u build the your project thought android-ndk that automatic created  the libs folder in over project



--
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.


Angus Lees

unread,
Jan 16, 2011, 11:48:55 PM1/16/11
to andro...@googlegroups.com
Most of this is noise. The real error is:

01-14 12:25:01.854: WARN/dalvikvm(31940): No implementation found for
native Lcom/eg/ncd/NativeLib;.add (II)I

In particular, it looks like it survived run-time linking so it looks
like you have built and packaged your native library correctly.

Work out why Java can't find the "static native int
com.eg.ncd.NativeLib.add(int, int)" function.

- Gus

nissar ka

unread,
Jan 20, 2011, 2:24:46 AM1/20/11
to android-ndk
As I told in the begining, i'm very new to android ndk(i know how to
build the libraries from source code and use in application).

I'm using android sdk with eclipse in windows. I've some third party
native libraries. Initially I tried just copying the librraies to ~/
libs/armeabi. But it didn't work. I got the same exception as shown
above.

What I want to know that is it required to specify anywhere that
native-lib-path="libs" something like this.

I don't think just copying the librraies will work. We have to specify
somewhere that our application is using these libraries.
Anybody could please explain me from the starting that how to use pre-
built libraries in our application.
Thanks and regards Nissar.

Mike Edenfield

unread,
Jan 20, 2011, 8:28:15 AM1/20/11
to andro...@googlegroups.com, nissar ka
On 1/20/2011 2:24 AM, nissar ka wrote:
> As I told in the begining, i'm very new to android ndk(i know how to
> build the libraries from source code and use in application).
>
> I'm using android sdk with eclipse in windows. I've some third party
> native libraries. Initially I tried just copying the librraies to ~/
> libs/armeabi. But it didn't work. I got the same exception as shown
> above.

docs/PREBUILTS.html

nissar ka

unread,
Jan 24, 2011, 7:27:27 AM1/24/11
to android-ndk

> docs/PREBUILTS.html

I've tried with 'ndk-build' with the following options in Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libMyTestNCL-prebuilt
LOCAL_SRC_FILES := libMyTestNCL.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

(I got this from docs/PREBUILTS.html )

But still it's not working. Am I missing something in Android.mk or
any other step?

Mike Edenfield

unread,
Jan 24, 2011, 11:56:09 AM1/24/11
to andro...@googlegroups.com, nissar ka

A couple things to check for:

The LOCAL_SRC_FILES are looked for relative to Android.mk, so if those
.so files are in a subfolder or somewhere else you'll need a relative
path to it:

LOCAL_SRC_FILES := libs/libavformat.a

Also, you didn't include the rest of the Android.mk, but make sure you
included the pre-built module in your primary output module. Also,
there is a typo in the docs; the variable used to list shared library
modules is:

LOCAL_SHARED_LIBRARIES := libMyTestNCL-prebuilt

--Mike

nissar ka

unread,
Jan 25, 2011, 5:29:22 AM1/25/11
to android-ndk
That's all my Android.mk file. Anything else i missed to add?
And how to "include the pre-built module in primary output module"?
> --Mike- Hide quoted text -
>
> - Show quoted text -

Android Developer

unread,
Feb 28, 2011, 5:04:14 AM2/28/11
to android-ndk
Hi,

Did you get any solution for this?
Even i am facing the issue. When i try to call a function from the pre
built library, it says undefined reference.
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages