Android -“不能加载Foo: findLibrary返回null”

时间:2022-09-08 13:43:52

I know that there are already posts about this error around stack overflow, but from what I have found here on SO and on Google don't line up with my problem.

我知道在stack overflow上已经有关于这个错误的帖子了,但是我在这里发现的和谷歌上的帖子都没有解决我的问题。

I am trying to run my application, but whenever a native function is called my program crashes, and I get the following LogCat...

我正在尝试运行我的应用程序,但是每当一个本机函数被称为我的程序崩溃时,我就会得到下面的LogCat…

08-01 09:15:57.448: E/AndroidRuntime(16966): FATAL EXCEPTION: main
08-01 09:15:57.448: E/AndroidRuntime(16966): java.lang.ExceptionInInitializerError
08-01 09:15:57.448: E/AndroidRuntime(16966):    at my.eti.commander.MainMenu.initMain(MainMenu.java:241)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at my.eti.commander.MainMenu.onCreate(MainMenu.java:81)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.os.Looper.loop(Looper.java:130)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at java.lang.reflect.Method.invoke(Method.java:507)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at dalvik.system.NativeStart.main(Native Method)
08-01 09:15:57.448: E/AndroidRuntime(16966): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load RelayAPI: findLibrary returned null
08-01 09:15:57.448: E/AndroidRuntime(16966):    at java.lang.Runtime.loadLibrary(Runtime.java:429)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at java.lang.System.loadLibrary(System.java:554)
08-01 09:15:57.448: E/AndroidRuntime(16966):    at my.eti.commander.RelayAPIModel$NativeCalls.<clinit>(RelayAPIModel.java:432)
08-01 09:15:57.448: E/AndroidRuntime(16966):    ... 15 more

Here is my Android.mk file:

这是我的Android。可文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
EXTRA_CFLAGS := -DANDROID
LOCAL_MODULE := RelayAPI
LOCAL_SRC_FILES := RelayAPI.c
include $(BUILD_EXECUTABLE)

Here is a picture of my jni folder...Only RelayAPI will be used, stringstuff is an extra file that isn't used.

这是我的jni文件夹的图片…只有RelayAPI将被使用,stringstuff是一个不被使用的额外文件。

Android -“不能加载Foo: findLibrary返回null”

I store all of my native functions in a separate class so that they can be called statically. This isn't the problem though, because I've been moving them around quite a bit but I just decided this would be the best way for me to get it done.

我将我的所有本机函数存储在一个单独的类中,这样它们就可以被静态地调用。这不是问题,因为我已经把它们移动了很多,但是我决定这将是我完成它的最好的方式。

public static class NativeCalls {

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

    public native static byte InitRelayJava();

    public native static void FreeRelayJava();
}

5 个解决方案

#1


1  

shouldn't include $(BUILD_SHARED_LIBRARY) be used instead of include $(BUILD_EXECUTABLE)?

不应该包括$(BUILD_SHARED_LIBRARY),而不是$(BUILD_EXECUTABLE)?

#2


1  

Well, I've gotten passed the error. I had asked a different question last month, and while trying to solve that, this error went away. It had to do with setting my environment PATH variable to the NDK folder location. This is a link to a more in depth answer.

我已经通过了这个错误。上个月我问了一个不同的问题,当我试图解决这个问题时,这个错误就消失了。它需要将我的环境路径变量设置为NDK文件夹位置。这是一个更深层次答案的链接。

#3


1  

Make sure to build your library before running your application (that use the library) with ndk-build

在运行应用程序(使用库)和ndk构建之前,确保构建您的库。

#4


0  

BUILD_EXECUTABLE is wrong, this will build an executable (hint, hint..) instead of a shared library. When you use System.loadLibrary(..) you have to use BUILD_SHARED_LIBRARY. If it still does not work, there might be another mistake but using BUILD_EXECUTABLE for something intended to be used as a shared library is wrong even though it 'may' work under some circumstances.

构建可执行文件是错误的,这将构建一个可执行文件(提示,提示.),而不是共享的库。当您使用System.loadLibrary(..)时,必须使用BUILD_SHARED_LIBRARY。如果它仍然不工作,可能会出现另一个错误,但是使用build_可执行文件作为共享库是错误的,即使它在某些情况下可能会工作。

#5


0  

I've got this issue too, but for my situation, You have to add processor based library to your project libs folder. If you are using eclipse.

我也有这个问题,但是在我的情况下,您必须将基于处理器的库添加到项目libs文件夹中。如果您正在使用eclipse。

Android -“不能加载Foo: findLibrary返回null”

#1


1  

shouldn't include $(BUILD_SHARED_LIBRARY) be used instead of include $(BUILD_EXECUTABLE)?

不应该包括$(BUILD_SHARED_LIBRARY),而不是$(BUILD_EXECUTABLE)?

#2


1  

Well, I've gotten passed the error. I had asked a different question last month, and while trying to solve that, this error went away. It had to do with setting my environment PATH variable to the NDK folder location. This is a link to a more in depth answer.

我已经通过了这个错误。上个月我问了一个不同的问题,当我试图解决这个问题时,这个错误就消失了。它需要将我的环境路径变量设置为NDK文件夹位置。这是一个更深层次答案的链接。

#3


1  

Make sure to build your library before running your application (that use the library) with ndk-build

在运行应用程序(使用库)和ndk构建之前,确保构建您的库。

#4


0  

BUILD_EXECUTABLE is wrong, this will build an executable (hint, hint..) instead of a shared library. When you use System.loadLibrary(..) you have to use BUILD_SHARED_LIBRARY. If it still does not work, there might be another mistake but using BUILD_EXECUTABLE for something intended to be used as a shared library is wrong even though it 'may' work under some circumstances.

构建可执行文件是错误的,这将构建一个可执行文件(提示,提示.),而不是共享的库。当您使用System.loadLibrary(..)时,必须使用BUILD_SHARED_LIBRARY。如果它仍然不工作,可能会出现另一个错误,但是使用build_可执行文件作为共享库是错误的,即使它在某些情况下可能会工作。

#5


0  

I've got this issue too, but for my situation, You have to add processor based library to your project libs folder. If you are using eclipse.

我也有这个问题,但是在我的情况下,您必须将基于处理器的库添加到项目libs文件夹中。如果您正在使用eclipse。

Android -“不能加载Foo: findLibrary返回null”