namuol
namuol

Reputation: 9996

Why isn't libgnustl_shared.so being copied from my APK?

I have an android project with a libs folder structure like this:

/libs
  /armeabi
    libfoo.so
    libbar.so
    libmystuff.so
    libgnustl_shared.so
  /armeabi-v7a
    libfoo.so
    libbar.so

foo and bar are third party libraries, mystuff is my own library from a separate android JNI project which requires gnustl_shared, which is from the same JNI project.

When I build my project in Eclipse, I can view the contents of the generated APK using unzip -l, and it indeed shows that all of these library files have been included.

However, after installing the APK, the /data/data/com.myproject/lib folder contains no libgnustl_shared.so, even though the other libraries are present.

This inevitably leads to the following error:

UnsatisfiedLinkError: Couldn't load gnustl_shared: findLibrary returned null

As a sanity check, I ran adb push ./libs/armeabi/libgnustl_shared.so /data/data/com.myproject/lib and sure enough, the application starts as expected.

I don't see anything in the build log or Eclipse console that suggests there were any issues building or installing the app.


Please let me know in a comment if there's any specific information I can provide that might help.

Upvotes: 9

Views: 10680

Answers (3)

jcm
jcm

Reputation: 2578

I think that, in your JNI project's Android.mk file, most probably, when you build libmystuff.so, you're referencing libgnustl_shared.so like:

LOCAL_LDLIBS += -lgnustl_shared

Maybe you can try to add it as a module (NDK works really focused on modules), something like:

include $(CLEAR_VARS) 
LOCAL_MODULE := gnustl_shared 
LOCAL_SRC_FILES := libgnustl_shared.so
include $(PREBUILT_SHARED_LIBRARY)

and (in the section you're building libmystuff.so):

LOCAL_SHARED_LIBRARIES := gnustl_shared

And check if it's finally copied

Upvotes: 2

PirateDave
PirateDave

Reputation: 161

Look at the answer here: How to link any library in ndk application The problem is most likely in your Android.mk file. You should have a line like the one on the bottom:

include $(BUILD_SHARED_LIBRARY)

If not, then you're not including your shared library.

Upvotes: 0

caopeng
caopeng

Reputation: 944

I think your libgnustl_shared.so need under /armeabi-v7a not under /armeabi

Please try copy libgnustl_shared.so to /armeabi-v7a

Upvotes: 0

Related Questions