Thursday, June 16, 2011

Logging in Native Code of Android

Today when i was working on native c code my printf didnt get logged so I experimented on how to put logs in native code which gets logged in logcat.

Below is the steps which i followed, hope it might help someone.

Step1: Included following header and log statement to get printed in logcat
           #include<android/log.h>
           __android_log_print(ANDROID_LOG_INFO, "MYPROG", "Hello i am inside jni");

Step2: Included below statements inside my Android.mk
          LOCAL_SHARED_LIBRARIES := libcutils

I followed the below link
https://groups.google.com/group/android-ndk/browse_thread/thread/2e27ecb1fa834c1c

LOCAL_LDLIBS := -llog,  didnt work for me as mentioned in the above link. The reason might be I am including my source code(JNI code) inside android source build system rather than building via NDK . I was getting Linker error because it was not able to get the reference for "__android_log_print"

In your android source code you will get libcutils already built as shared library under out/target/product/generic/obj/SHARED_LIBRARIES/libcutils_intermediates, so only reference to this lib as in step 2: above will work.


Please provide me any suggestions :-)








2 comments:

  1. How should i write this " LOCAL_SHARED_LIBRARIES := libcutils" in Makefile.common

    ReplyDelete
  2. JJ means in the Makefile.common that is located in source code of Android emulator, and particularly in the qemu extrnal directory I think.

    ReplyDelete