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
obj)
{
      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, "com.android.Test.show");


        meth.name = "show";
        meth.signature = "()V";
        meth.fnPtr = Java_com.android.Test.show;
        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, "com.android.Test.show");
        (*env)->UnregisterNatives(env, k);


}


While executing on Android the following messages are obeserved in adb
logcat.

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

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.

Regards,
-Siva.
--~--~---------~--~----~------------~-------~--~----~



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 Android.mk I use:

LOCAL_STATIC_LIBRARIES += vendorlib
PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/$(VENDOR_LIB_PATH)/vendorlib.a:obj/lib/vendorlib.a

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/
symbols/system/lib/libvendor_jni)
make: *** No rule to make target `NOTICE-TARGET-STATIC_LIBRARIES-
vendorlib', needed by `out/target/product/umts_xxx/system/lib/
libvendor_jni.so'.  Stop.


So I have to change it to:

LOCAL_PREBUILT_LIBS := vendorlib
include $(BUILD_PREBUILT)

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

Who knows hopw to solve the problem?

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. missing /etc/localtime

Hi

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?
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

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