eclipse UnsatisfiedLinkError: ... :findLibrary 返回 null

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22119367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:33:04  来源:igfitidea点击:

UnsatisfiedLinkError: ... :findLibrary returned null

androideclipseubuntuandroid-ndkjava-native-interface

提问by Steve Schwarcz

03-01 14:00:53.556: E/AndroidRuntime(27208): java.lang.UnsatisfiedLinkError: Couldn't load
example from loader dalvik.system.PathClassLoader[DexPathList[[zip file 
"/data/app/com.example.test-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.test-
2, /vendor/lib, /system/lib]]]: findLibrary returned null

I am trying to get a basic environment set up for Android NDK development on Ubuntu 12 and I cannot get this error to go away. My system is already set up for regular Android development with the SDK. I've installed the eclipse C/C++ development tools.

我正在尝试为 Ubuntu 12 上的 Android NDK 开发设置一个基本环境,但我无法消除此错误。我的系统已经设置为使用 SDK 进行常规 Android 开发。我已经安装了 eclipse C/C++ 开发工具。

My .bashrc has these lines at the bottom:

我的 .bashrc 在底部有这些行:

NDK_HOME=~/android-ndk-r9c
export NDK_HOME
export PATH=/home/steve/android-ndk-r9c:${PATH}
export NDK_PATH=/home/steve/android-ndk-r9c

In my Eclipse properties, my NDK location in Android->NDK is set to /home/steve/android-ndk-r9c. My Android.mk looks as follows:

在我的 Eclipse 属性中,我在 Android->NDK 中的 NDK 位置设置为 /home/steve/android-ndk-r9c。我的 Android.mk 如下所示:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := test
LOCAL_SRC_FILES := example.c

include $(BUILD_SHARED_LIBRARY)

I tried using build-ndk on the command line. I now have in my project directory a file obj/local/armeabi/libtest.so, but it's not doing me any good.

我尝试在命令行上使用 build-ndk。我现在在我的项目目录中有一个文件 obj/local/armeabi/libtest.so,但这对我没有任何好处。

For what it's worth, no project works, not even the NDK sample projects (such as HelloJni). What can I do to compile a basic JNI application?

就其价值而言,没有任何项目有效,甚至 NDK 示例项目(例如 HelloJni)也不行。如何编译基本的 JNI 应用程序?

EDIT: This is on an actual device. The ndk-build output of hello-jni is:

编辑:这是在实际设备上。hello-jni 的 ndk-build 输出是:

[armeabi-v7a] Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup       : libs/armeabi-v7a/gdb.setup
[armeabi] Gdbserver      : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
[armeabi] Gdbsetup       : libs/armeabi/gdb.setup
[x86] Gdbserver      : [x86-4.6] libs/x86/gdbserver
[x86] Gdbsetup       : libs/x86/gdb.setup
[mips] Gdbserver      : [mipsel-linux-android-4.6] libs/mips/gdbserver
[mips] Gdbsetup       : libs/mips/gdb.setup
[armeabi-v7a] Compile thumb  : hello-jni <= hello-jni.c
[armeabi-v7a] SharedLibrary  : libhello-jni.so
[armeabi-v7a] Install        : libhello-jni.so => libs/armeabi-v7a/libhello-jni.so
[armeabi] Compile thumb  : hello-jni <= hello-jni.c
[armeabi] SharedLibrary  : libhello-jni.so
[armeabi] Install        : libhello-jni.so => libs/armeabi/libhello-jni.so
[x86] Compile        : hello-jni <= hello-jni.c
[x86] SharedLibrary  : libhello-jni.so
[x86] Install        : libhello-jni.so => libs/x86/libhello-jni.so
[mips] Compile        : hello-jni <= hello-jni.c
[mips] SharedLibrary  : libhello-jni.so
[mips] Install        : libhello-jni.so => libs/mips/libhello-jni.so

回答by Sebastiano

The right way of loading the shared library is

加载共享库的正确方法是

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

The library name is taken from the LOCAL_MODULEdefinition of your Android.mk file (or from the Application.mk file, if you decide to use it). In your case, you are naming your module test. The ndk-buildgenerates the shared library libtest.so.

库名称取自LOCAL_MODULEAndroid.mk 文件的定义(或取自 Application.mk 文件,如果您决定使用它)。在您的情况下,您将模块命名为test。该ndk-build生成的共享库libtest.so

Pay attention that you do not need to include the lib-prefix in the System.loadLibrary()call.

请注意,您不需要在调用中包含lib-前缀System.loadLibrary()