2

Background

I'm writing application for android, using Eclipse in Windows. I'm implementing C code in JAVA and for that I'm using JNI. I have many functions and my problem is that I want to debug functions in JNI.

Question

Can I debug my code which is written in JNI in C language ?

Community
  • 1
  • 1
Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147

1 Answers1

3

Here is answer How to start logging for Android NDK !

Some weeks I was researching how I can write logs in Eclipse from Android NDK code. I found some examples in Internet and want to share it with you. Following steps below you can start logging on Eclipse.

  1. Include log.h file into your Android NDK source file

    #include <android/log.h>
    
  2. Add the line below to your Android.mk make file.

    LOCAL_LDLIBS := -llog
    

Now you can start logging, this two steps allows you to write logs in Eclipse from Android NDK. Write the line below in your Android NDK code and the log will bw appear in the Eclipse

__android_log_write(ANDROID_LOG_ERROR,"Tag","Message");

use following Flags to write logs in the column which you want.

typedef enum android_LogPriority {
    ANDROID_LOG_UNKNOWN = 0,
    ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
    ANDROID_LOG_VERBOSE,
    ANDROID_LOG_DEBUG,
    ANDROID_LOG_INFO,
    ANDROID_LOG_WARN,
    ANDROID_LOG_ERROR,
    ANDROID_LOG_FATAL,
    ANDROID_LOG_SILENT,     /* only for SetMinPriority(); must be last */
} android_LogPriority

For example if you want to write in Info column you must write

__android_log_write(ANDROID_LOG_INFO,"Tag","Message");

So, Good Luck !

Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147
  • +1 its a nice answer... I also have some strange problem can you help me out http://stackoverflow.com/questions/11324340/surprise-behavior-of-eclipse-for-c-files-while-using-jni-why-so – Amit Jul 05 '12 at 05:40