9

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.

  • What could be preventing libgnustl_shared.so from being installed with my application?
  • Where can I go to learn about what happens when an APK is installed?

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

namuol
  • 9,816
  • 6
  • 41
  • 54
  • double check the mainfest for statements including all the libs. – Robert Rowntree Apr 25 '13 at 21:09
  • @RobertRowntree -- Could you explain what you mean? I've never needed to specify libraries in `AndroidManifest.xml` for other projects, if that's what you're referring to. – namuol Apr 25 '13 at 23:24
  • read here: http://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject – Robert Rowntree Apr 26 '13 at 03:22
  • 1
    This is for referencing other Android library projects that you have source access to. What I have is a combination of some `.jar` files, and some `.so` files. My `project.properties` file makes no references to other library projects, yet `libfoo`, `libbar`, and `libmystuff` are all installed correctly. The only missing library is `libgnustl_shared`. NDK development is anything but smooth. :[ – namuol Apr 26 '13 at 03:34
  • http://stackoverflow.com/questions/14687287/adding-prebuilt-apk-with-shared-libraries-to-aosp follow the link under the accepted answer for an explain on what happens during apk 'unpack' on the device and why shared libs may have to be copy manual – Robert Rowntree Apr 26 '13 at 04:33
  • It is packed to apk file but is not being unpacked to `/lib` on installation. That seems to be an issue on android side. Try removing the underscore '_' from the name. – S.D. Apr 29 '13 at 11:09
  • `libgnustl_shared.so` is a standard library that _ships_ with the android NDK -- Also, why would underscores magically break the findLibrary command? – namuol Apr 29 '13 at 11:37
  • @RobertRowntree - that link would only be relevant for APK's packaged **as part of the android system itself** and not for ordinary 3rd party APK's. – Chris Stratton Nov 22 '13 at 18:55

3 Answers3

2

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

jcm
  • 2,568
  • 14
  • 18
0

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

Please try copy libgnustl_shared.so to /armeabi-v7a

caopeng
  • 914
  • 13
  • 23
  • Hi @namuol ;if your couldn't find *libgnustl_shared.so* under `/data/data/com.myproject/lib` means this lib not be packed to your APK. – caopeng May 01 '13 at 04:46
  • @namuol are your appoint `APP_ABI` in `Application.mk`?by default ,the`APP_ABI` equals **armeabi**, – caopeng May 01 '13 at 04:54
  • 1
    No -- `libgnustl_shared.so` is actually in the apk. I have made certain of this. – namuol May 01 '13 at 12:37
  • @namuol,I think It's better to list your `.MK` files – caopeng May 01 '13 at 13:20
  • What would happen if you deleted the libs/armeabi-v7a directory and left just the armeabi dir in your source? – Ethan May 01 '13 at 16:34
0

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.

Community
  • 1
  • 1
PirateDave
  • 163
  • 1
  • 3
  • 11
  • I'm using this exact line in the JNI project where I got `libmystuff.so` and `libgnu_stl_shared.so`; the project I'm referring to in my question is not a JNI project, so no `Android.mk` file is necessary. – namuol May 04 '13 at 03:06