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. ADT With Karmic Koala

I've replied to a similar post, but it never seems to show up, so I'll
just post a new one.

I can't seem to get the ADT plugin installed, I go to Help->Install
New Software, add the adt url, the ADT items show up in the tree view,
but halfway through installation I get the messagebox that says
"Warning: you are installing software that contains unsigned
content...", I click OK, and I get this:

An error occurred while installing the items
  session context was:(profile=PlatformProfile,
operand=null --> [R]org.eclipse.ant.ui 3.4.1.v20090901_r351,
  The artifact file for osgi.bundle,org.eclipse.ant.ui,
3.4.1.v20090901_r351 was not found.

I've tried with the https, the http, AND the local archive I
downloaded from the developers site.

My setup:
AMD X2 64
Ubuntu 9.10 Karmic Koala
Eclipse 3.5.1 Galileo - installed through the software center
JDK 6.15.1

Is this an issue with Karmic because I had all this setup a few months
ago in Jaunty with no troubles.

Any ideas?


2. Getting "Hello, Android" to Run w/SDK 2.0

Brand new to Android, but using Eclipse for a while.

Using this tutorial:

I built the avm, set up my project for SDK 2.0 and made the code

However, when I run, instead of a minimal frame with "Hello, Android"
in it, it brings up a dual frame, with the words "A N D R O I D" on
the left, and a handset emulator on the left.   None of the buttons on
the handset are implemented.

There is no "Hello, Android" on the avm screen.

Can you tell me if this tutorial is still valid?

Is there an equivalent for the 2.0 SDK?


3. Tabs for a newbie

4. SQLiteDatabase update?

5. Widgets changes with 1.6?

6. Android desktop and Application.

7. Emulator crashed on X86_64 Gentoo (SDK 1.6)