4

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.

I am trying to run my application, but whenever a native function is called my program crashes, and I get the following 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:

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.

enter image description here

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();
}
JuiCe
  • 4,132
  • 16
  • 68
  • 119
  • i think the error is coming becoz of libs,,,,Add correctly jar files – shassss Aug 01 '12 at 13:31
  • Build it as a shared library. I think it may be because you're building it as an executable. I don't think System.loadLibrary can load executables – Mario Aug 01 '12 at 13:37
  • Where have you copied your jar/ or other Library files in your project?? – Chintan Raghwani Aug 01 '12 at 13:56
  • I really have no idea what files you're talking about, sorry. What purpose do the files serve? I have only been altering my .c/.h/.mk files in the jni folder and the Java files in my /src directory – JuiCe Aug 01 '12 at 13:59

5 Answers5

1

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

skj
  • 11
  • 1
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.

Community
  • 1
  • 1
JuiCe
  • 4,132
  • 16
  • 68
  • 119
1

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

Ashkan
  • 1,865
  • 16
  • 13
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.

chrulri
  • 1,822
  • 14
  • 16
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.

enter image description here

hrskrs
  • 4,447
  • 5
  • 38
  • 52