JNI_OnLoad not found !

4,233 views
Skip to first unread message

Houcem Berrayana

unread,
Feb 4, 2010, 10:33:21 AM2/4/10
to android-ndk
Hi,
I was checking the net for more than 2 days to fix a System.load
problem. I wrote a code in C. then I generated a header file using the
javah tool. I implemented the .h generated file. Then I used Cygwin to
build my library (gcc 3.81) and I am runnig on windows.
The problem is that I still get the same error even after trying more
than 10 ways !! I am stuck and I can't move on. Here is the log file:

02-03 18:01:59.117: DEBUG/dalvikvm(6102): Trying to load lib /data/
data/com.test.app/lib/libdrone.so 0x4470eec8
02-03 18:01:59.117: DEBUG/dalvikvm(6102): Added shared lib /data/data/
com.test.app/lib/libdrone.so 0x4470eec8
02-03 18:01:59.117: DEBUG/dalvikvm(6102): No JNI_OnLoad found in /data/
data/com.test.app/lib/libdrone.so 0x4470eec8
02-03 18:01:59.127: DEBUG/ViewFlipper(136): updateRunning()
mVisible=false, mStarted=true, mUserPresent=true, mRunning=false
02-03 18:01:59.147: DEBUG/SensorManager(6102): found sensor: BMA150 3-
axis Accelerometer, handle=0
02-03 18:01:59.147: DEBUG/SensorManager(6102): found sensor: AK8973 3-
axis Magnetic field sensor, handle=1
02-03 18:01:59.147: DEBUG/SensorManager(6102): found sensor: AK8973
Orientation sensor, handle=2
02-03 18:01:59.147: DEBUG/SensorManager(6102): found sensor: CM3602
Proximity sensor, handle=4
02-03 18:01:59.147: DEBUG/SensorManager(6102): found sensor: CM3602
Light sensor, handle=5
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libwebcore.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libmedia_jni.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libexif.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libsrec_jni.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: WARN/dalvikvm(6102): No implementation found for
native Lcom/test/app/DroneController;.nativeInit ()V
02-03 18:01:59.147: DEBUG/AndroidRuntime(6102): Shutting down VM
02-03 18:01:59.147: WARN/dalvikvm(6102): threadid=3: thread exiting
with uncaught exception (group=0x4001b178)
02-03 18:01:59.147: ERROR/AndroidRuntime(6102): Uncaught handler:
thread main exiting due to uncaught exception


Somebody can help me please ?

David Turner

unread,
Feb 4, 2010, 4:29:34 PM2/4/10
to andro...@googlegroups.com
No JNI_OnLoad is perfectly normal, it's only a debug message. The problem seems to be later:

02-03 18:01:59.147: WARN/dalvikvm(6102): No implementation found for
native Lcom/test/app/DroneController;.nativeInit ()V

Are you sure you implemented Java_com_test_app_DroneController_nativeInit
correctly and used extern "C" linkage, in case it was implemented in C++ ?


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Houcem Berrayana

unread,
Feb 4, 2010, 5:01:11 PM2/4/10
to android-ndk
I implemented nativeInit as following:

JNIExport void
Java_com_parrot_ARDrone_DemoRenderer_nativeInit( JNIEnv* env )
{
//importGLInit();
appInit();
sDemoStopped = 0;
sTimeOffsetInit = 0;
}

I am not sure if it begins by JNIExport or not but it should be
something like that. It's the same as the generated .h file (using
javah). In the .h file these methods are declared as exter "C" .
Should I declare extern "C" in the .c file also ?

fadden

unread,
Feb 4, 2010, 6:21:53 PM2/4/10
to android-ndk
On Feb 4, 2:01 pm, Houcem Berrayana <houcem.berray...@gmail.com>
wrote:

> JNIExport void
> Java_com_parrot_ARDrone_DemoRenderer_nativeInit( JNIEnv*  env )

The error message says:

No implementation found for native Lcom/test/app/
DroneController;.nativeInit ()V

So it's looking for Java_com_test_app_DroneController_nativeInit
(assuming you're not registering functions manually).

Houcem Berrayana

unread,
Feb 5, 2010, 3:57:15 AM2/5/10
to android-ndk
Here is the function implementation in android.c

JNIEXPORT void
Java_com_test_app_DroneController_nativeInit( JNIEnv* env ,jobject
thiz)


{
//importGLInit();
appInit();
sDemoStopped = 0;
sTimeOffsetInit = 0;
}

and here is the declaration in android.h file (generated using javah
tool)

extern "C" {
#endif
/*
* Class: com_parrot_ardrone_app_DroneController
* Method: nativeInit
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_app_DroneController_nativeInit
(JNIEnv *, jobject);

#ifdef __cplusplus
}


I'm running on windows SP3 using cygwin and gcc 3.81.

In the log file , libadrone.so is loaded but the dalvikVm never seeks
the nativeInit function there :

02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libwebcore.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libmedia_jni.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libexif.so' for 'nativeInit' (wrong CL)
02-03 18:01:59.147: DEBUG/dalvikvm(6102): +++ not scanning '/system/
lib/libsrec_jni.so' for 'nativeInit' (wrong CL)

02-03 18:01:59.147: WARN/dalvikvm(6102): No implementation found for
native Lcom/test/app/DroneController;.nativeInit ()V

Should I implement JNI_OnLoad by my self ?

Message has been deleted

Houcem Berrayana

unread,
Feb 5, 2010, 11:36:21 AM2/5/10
to android-ndk
Worked for me.. I don't know how but I suddenly started to work. Thank
you very much for your help :)

On Feb 5, 9:57 am, Houcem Berrayana <houcem.berray...@gmail.com>
wrote:

gacon

unread,
Aug 24, 2010, 10:52:33 AM8/24/10
to David Turner, andro...@googlegroups.com
Hi, The same problem for me. I always get the message "No
implementation found for native xxx".

I don't know how to fix this. I'm testing with the example hello-gl2.

I just doubled the function public static native void init(int width,
int height);, replace function name "init" by "test".

Then go to gl_code.cpp, double the function JNIEXPORT void JNICALL
Java_com_android_gl2jni_GL2JNILib_init(JNIEnv * env, jobject obj,
jint width, jint height);, replace function name "init" by "test".

Then implement

JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_test(JNIEnv *
env, jobject obj, jint width, jint height)
{

}


and build project, then run and get the error message.

Thanks,

On Feb 4, 11:29 pm, David Turner <di...@android.com> wrote:
> No JNI_OnLoad is perfectly normal, it's only a debug message. The problem
> seems to be later:
>
> 02-03 18:01:59.147: WARN/dalvikvm(6102): No implementation found for
> native Lcom/test/app/DroneController;.nativeInit ()V
>
> Are you sure you implemented Java_com_test_app_DroneController_nativeInit
> correctly and used extern "C" linkage, in case it was implemented in C++ ?
>

> On Thu, Feb 4, 2010 at 7:33 AM, Houcem Berrayana <houcem.berray...@gmail.com

> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>

alan

unread,
Aug 26, 2010, 5:14:46 AM8/26/10
to android-ndk
is your function declared inside an 'extern "C"' block?

Ngo Van Luyen

unread,
Aug 26, 2010, 7:44:39 AM8/26/10
to andro...@googlegroups.com
yes, sure


2010/8/26 alan <al...@birtles.org.uk>
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
Hello Android!
http://androidcore.com/

Christian Linne

unread,
Aug 26, 2010, 8:06:16 AM8/26/10
to andro...@googlegroups.com
 public static native void init(int width,
int height);, replace function name "init" by "test".
 
[...]

JNIEXPORT void JNICALL Java_com_android_gl2jni_GL2JNILib_test(JNIEnv *
env, jobject obj,  jint width, jint height) 
These definitions do not fit.
 
Also, remember to recreate the headerfile, if you haven't done that yet.
 
2010/8/26 Ngo Van Luyen <nvlu...@gmail.com>



--
_________
Mit freundlichen Grüßen
Yours sincerely

Christian Linne

Mail (private): linn...@aol.com
Mail (official): Christi...@googlemail.com,
ICQ: 293253013

Ngo Van Luyen

unread,
Aug 26, 2010, 8:53:53 AM8/26/10
to andro...@googlegroups.com
Hi, could you tell me why it does not fit? what's the difference?

There is no header file in this case, there is only one cpp file

thanks,

2010/8/26 Christian Linne <christi...@googlemail.com>

mic _

unread,
Aug 26, 2010, 9:31:20 AM8/26/10
to andro...@googlegroups.com
A static method belongs to the class, not to a specific instance. It'll receive a jclass rather than a jobject.

/Michael

Ngo Van Luyen

unread,
Aug 26, 2010, 9:45:23 AM8/26/10
to andro...@googlegroups.com
hi, I did'nt change the data type. You can take a look into example or check this: http://java.sun.com/docs/books/jni/html/start.html


JNIEXPORT void JNICALL 
 Java_HelloWorld_print(JNIEnv *env, jobject obj)
 {
     printf("Hello World!\n");
     return;
 }



2010/8/26 mic _ <mico...@gmail.com>

Christian Linne

unread,
Aug 26, 2010, 9:54:45 AM8/26/10
to andro...@googlegroups.com
In the example you mentioned, the call came from a particular object (that was created on-the-fly), so getting the jobject-reference is normal. If a method is declared as static, it does not belong to a particular instance, but to the class, so the reference of the class gets handled over.
there is only one cpp file
Would be curious if it works under that circumstances. Generate a particular header and try again :)

Ngo Van Luyen

unread,
Aug 26, 2010, 10:02:19 AM8/26/10
to andro...@googlegroups.com
It's working now, what's magic, Eclipse!

Solution: Change module name in the Android.mk file, I changed it to: LOCAL_MODULE    := libgl2jni2 (and don't forget to change in System.loadLibrary("gl2jni2");)
Then open Manifest file, try to modify something (just add an enter at the end of file)

Then run again, eclipse will rebuild and re-package everything, and it works!



2010/8/26 Christian Linne <christi...@googlemail.com>

Tim in Boulder

unread,
Aug 26, 2010, 12:29:28 PM8/26/10
to android-ndk
On Aug 26, 8:02 am, Ngo Van Luyen <nvluye...@gmail.com> wrote:
> Solution: Change module name in the Android.mk file, I changed it
> to: LOCAL_MODULE    := libgl2jni2 (and don't forget to change in
> System.loadLibrary("gl2jni2");)
> Then open Manifest file, try to modify something (just add an enter at the
> end of file)
>
> Then run again, eclipse will rebuild and re-package everything, and it
> works!

I was wondering if this was a dependency/package build problem. I've
seen that again and again--even after following the instructions on
getting dependencies "working" with the NDK in Eclipse.

Funny thing is that SOMETIMES it works--a new .so build ends up
triggering a repackage of the .apk. But sometimes it doesn't.

So when I want to be sure, I always force it to rebuild at least one
Java file. Sigh. Maybe I should be looking into the Ant build
process...

Tim

Christian Linne

unread,
Aug 26, 2010, 1:45:50 PM8/26/10
to andro...@googlegroups.com
A rebuild will always be introduced when Eclipse recognizes that some important parts of the project have changed, most easily, when you remove the apk. Up to now, a freshly rebuilt .so isn't enough for it, because it has only a loose binding to the rest of the project that only takes effect during runtime.
You will get a similar effect if you change some parts of the project through the regular file system and try to use them afterwards - Eclipse will not recognize automatically that they have been changed.
An option may be to include the lib-building-process into the regular one by defining a new builder that includes the build-scripts from the NDK... honestly, I like that option, and I'm already working with it.

2010/8/26 Tim in Boulder <tim.m...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Reply all
Reply to author
Forward
0 new messages