Native code is being called successfully but not executed properly

by pink 444 » Thu, 10 Sep 2009 12:37:42 GMT

Sponsored Links
 hai folks,

            In Android , Native code is written as follows.

JNIEXPORT void JNICALL Java_com_android_Test_show(JNIEnv *env, jobject
      printf("THIS IS TEST");

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
        JNIEnv *env;
        JNINativeMethod meth;
        jclass k;
        jint r;

        r = (*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4);
        k = (*env)->FindClass (env, "");
 = "show";
        meth.signature = "()V";
        meth.fnPtr =;
        r = (*env)->RegisterNatives (env, k, &meth, 1);
        return JNI_VERSION_1_4;


JNIEXPORT void JNI_OnUnload(JavaVM *vm, void *reserved)
        JNIEnv *env;
        jclass k;
        jint r;
        r = (*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_4);
        k = (*env)->FindClass (env, "");
        (*env)->UnregisterNatives(env, k);


While executing on Android the following messages are obeserved in adb

JNI     (  524): Trying to load jni .so
I/System.out(  524): /system/lib
D/dalvikvm(  524): Trying to load lib /data/ 0x433f22d0
D/dalvikvm(  524): Added shared lib /data/ 0x433f22d0
I/ActivityManager(   50): Displayed activity

But "THIS IS TEST" is not being displayed, which is displayed in
native code.

There are no errors regarding loading shared library and calling
native code.Then why is the message is not displayed in logging.

Am i doing any mistake.If JNI_OnLoad and JNI_OnUnLoad are not
implemented i am getting errors in Logging.If i do as above i not
getting that native code message.

Any help would be appreciated highly.


Other Threads

1. Link error when link with 3rd party static library

I need to link the static library provided by 3rd party to a shared
library,and in the I use:


The compile and link works in the previous android release.But now I
met error:
make: Circular .so <- .so dependency dropped.
make: Circular .so <- out/target/product/umts_xxx/symbols/system/lib/
libvendor_jni dependency dropped.
make: Circular .so <- .so dependency dropped.
target Non-prelinked: libvendor_jni (out/target/product/umts_xxx/
make: *** No rule to make target `NOTICE-TARGET-STATIC_LIBRARIES-
vendorlib', needed by `out/target/product/umts_xxx/system/lib/'.  Stop.

So I have to change it to:


But I still met error:
build/core/ *** dont use LOCAL_PREBUILT_LIBS anymore
LOCAL_PATH=frameworks/base/vendor/jni.  Stop.

Who knows hopw to solve the problem?


2. missing /etc/localtime


I want to port an C native application using '/etc/localtime' but in
cupcake image there is no /etc/localtime. In order to support this
feature, please let me know how to handle or ant other suggestion?

3. overlay controls on a splash screen

4. GPS ,accuracy of the GPS receiver

5. Apps referencing each other's classes?

6. How put "bold" to "android:textStyle" of a TextView from RemoteViews ?

7. TabHost problem with designing Tabs