Home » Android » android – No JNI_OnLoad found in … skipping init

android – No JNI_OnLoad found in … skipping init

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’ve been getting this message for the past day or so, and up until now it hasn’t caused a problem. I got my code to run with my native library earlier but today I added a few new functions and again it will not work.

There are no errors displayed in LogCat, but my program just opens and closes instantly on my device. There is no message saying that the application has stopped unexpectedly, just a black flash across the screen.

I have looked around google and SO but there are SO many different reasons for this message to come up. Here is my LogCat :

08-03 10:44:50.186: D/dalvikvm(2143): Trying to load lib /data/data/my.eti.commander/lib/libRelayAPI.so 0x40514f58
08-03 10:44:50.186: D/dalvikvm(2143): Added shared lib /data/data/my.eti.commander/lib/libRelayAPI.so 0x40514f58
08-03 10:44:50.186: D/dalvikvm(2143): No JNI_OnLoad found in /data/data/my.eti.commander/lib/libRelayAPI.so 0x40514f58, skipping init
08-03 10:44:50.288: I/DEBUG(1058): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-03 10:44:50.288: I/DEBUG(1058): Build fingerprint: 'LENOVO/IdeaPad_Tablet_A1_07/A1_07:2.3.4/GRJ22/eng.user.20120209.100319:user/release-keys'

What I would like to know is :

1) Is this No JNI_OnLoad message causing my program to not open?

2) If so, I know I have none of my code posted, but could someone explain the general idea of this message. Including what init it is skipping.

EDIT :

The new functions I added today were commented out when this happened. I had originally gotten a different error, and wanted to make sure my old code was still working.

How to&Answers:

The function JNI_OnLoad is not essential. Thus, if you have not provided this function, your program should run normally.

Your problem come from another part of your code. Try to use ndk-gdb to fix it.

Answer:

Here as @djedge mentioned JNI_OnLoad is just a warning. Most probably there are two main reasons for this.
First one is something wrong with your Android.mk file. Normally it should be look like

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    OPENCV_CAMERA_MODULES:=on
    OPENCV_INSTALL_MODULES:=on
    #OPENCV_LIB_TYPE:=SHARED
    include D:\NDK\MyApplication3\libraries\native\jni\OpenCV.mk
    LOCAL_SRC_FILES  := DetectionBasedTracker_jni.cpp
    LOCAL_C_INCLUDES += $(LOCAL_PATH)
    LOCAL_LDLIBS     += -llog -ldl
    LOCAL_MODULE     := detection_based_tracker
    include $(BUILD_SHARED_LIBRARY) 

here please give some attention on LOCAL_SRC_FILES whether correct c/c++ source file is provided.

Nest problem would be lie in your function signatures. If you generated header files and those function signatures should be match to your c/c++ file function/method definitions.

Here is an example.
Header file

  JNIEXPORT jlong JNICALL Java_com_example_jobs_myapplication_DetectionBasedTracker_nativeCreateObject

(JNIEnv *, jclass, jstring, jint);

C++ file

 JNIEXPORT jlong JNICALL  Java_com_example_jobs_myapplication_DetectionBasedTracker_nativeCreateObject
 (JNIEnv * jenv, jclass, jstring jFileName, jint faceSize)
  {

   //code goes here...
  }

Here com_example_jobs_myapplication might be wrong.