Android load native library

戏子无情 提交于 2019-12-05 17:07:18

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.

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.

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.

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

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!