6

I'm trying to load a library I built with the standalone NDK toolchain.

I built libGLmove.so and placed it in libs/armeabi of my Eclipse project

However, the call to System.loadLibrary("GLmove") throws an UnsatisfiedLinkError

Any ideas as to how to resolve the problem or make Android find my library? How does ndk-build package the library after it builds it?

Edit: The exact compile flags are:

/Users/thomas/Documents/android-ndk-r5b/toolchains/arm-eabi-4.4.0/prebuilt/darwin-x86/bin/arm-eabi-g++ --sysroot=/Users/thomas/Documents/android-ndk-r5b/platforms/android-8/arch-arm -march=armv7-a -mfloat-abi=softfp -mfpu=neon -Wl,--fix-cortex-a8 -fno-exceptions -fno-rtti -nostdlib -fpic -shared -o GLmove.so -O3

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Prime
  • 4,081
  • 9
  • 47
  • 64

5 Answers5

5

Have you checked in the resulting .APK file (use a zip utility to look at/unarchive it) to see if your library makes it through packaging? I'm a little suspicious that it might not, because I notice that everything that gets built into the "libs" folder in the project and on my build machine goes into a folder called "lib" (no 's') in the APK.

I wouldn't be too surprised if it turned out that the Eclipse build process doesn't package up any libraries it doesn't know about. This is, of course, unlike what happens with resources, which just get packaged by virtue of being in the right place.

If you find your library is not in your APK file, I don't think you can just manually put it in there, since it won't show up in the package manifest and will break any signing as well.

You don't mention whether or not your Eclipse project is an NDK project (right click on the project, Android Tools->Add Native Support.) If not, I suspect you'll need to make it into one and then add your library to the Android.mk file as a dependency and not a target.

Or: you could try putting your library into /res in the project and use System.load() instead of System.loadLibrary() to load it. I'll admit that I've never tried that myself, tho.

jimkberry
  • 1,317
  • 7
  • 8
  • Ok, so I shoulda tried it before typing. Turns out if I put a /libs folder into a non-NDK eclipse projects and drop /areabi/libSomething.so into THAT, then just do a normal eclipse project build, the resulting APK DOES have /lib/armeabi/libSomething.so, and it's in the manifest and everything so that's not likely to be it. On the other hand, doesn't the use of -march=armv7-a in your build line imply that the architecture folder should be "/armeabi-v7a" and not "/armeabi"? That's what I get when I use the ndk-build stuff. – jimkberry Jun 09 '11 at 19:24
  • 1
    thanks very much for the reply! I went through the APK after unzipping it and it is included, I don't have the Android Tools->Add Native Support option in Eclipse. Why is that? I just updated the ADT with Help->Check for Updates – Prime Jun 10 '11 at 02:34
  • 1
    Can you install your app on an emulator? If so, do it, then go to a DDMS view in eclipse, select the emulator device and "File Explorer" and look in: /data/data/your.package.name/lib. Is your library there? – jimkberry Jun 10 '11 at 14:37
  • yes, it installs on an emulator and is located in that directory. its named libglmove.so. I tried a call to System.loadLibrary("glmove"); and get the same error – Prime Jun 10 '11 at 16:36
2

I was running into this same problem. The things I had wrong.

  1. In the make file I had the "LOCAL_SRC_FILES" spelled wrong.
  2. In the c source file I had the library name inside the method name

Java_com_my_namespace_libname_activity_methodName(JNIEnv* env, jobject _this) {
//Fancy Native Junk Here
}

Once I fixed those two things, re-ran ndk-build and refreshed the eclipse project with F5 it started to work.

zznq
  • 400
  • 1
  • 15
  • This question is specifically dealing with the standalone compiler... correct me if I'm wrong but I don't think the standalone compiler makes use of the Android.mk file? – Prime Jun 04 '11 at 05:45
  • I don't know if it does or not. I would think unless a different make file is defined the compiler would use the Android.mk file, but that might just be a poor assumption by me. – zznq Jun 10 '11 at 16:29
2

You don't give very many details, but it may be that the .so you've built relies on a library that isn't available on the version of phone you're using.

I've not found any way to tell the NDK which Android SDK version you're targeting so don't have any very clear idea of how this side of it should work, but it looks like it would be easy to bring in a dependency from a newer SDK version into your .so so it won't load on all phones.

KayEss
  • 2,290
  • 15
  • 31
1

Could you please check the syntax and the location of System.loadLibrary("GLmove")

the System.loadLibrary call should be in static block of the Java source file

static {
    System.loadLibrary("nativelib");
}

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html

Shrenik
  • 399
  • 2
  • 5
  • 22
  • Sorry, but... "The library can be loaded outside of the static block if your application requires it." Would imply this isn't necessary, and I get the same Exception thrown anyway. – Prime Jun 02 '11 at 15:24
1

If your native library needs other libraries you'll need to load them first. If that doesn't help, check to see that your project directory does not contain spaces.

Also, you may find this tutorial helpful: http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

Ed Burnette
  • 1,198
  • 8
  • 13