if i am defining such function in java file
/**
* Adds two integers, returning their sum
*/
public native int add( int v1, int v2 );
so i need to code in c file
JNIEXPORT jint JNICALL Java_com_marakana_NativeLib_add
(JNIEnv * env, jobject obj, jint value1, jint value2) {
printf("\n this is log messge \n");
return (value1 + value2);
}
then from where this printf will print it message ?
In logcate i dont get it?
How can i debug any NDK application by putting log messages?
use
__android_log_print()instead. You have to include header<android/log.h>Sample Example.
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n this is log messge \n");You can also use format specifier like printf –
Make sure you also link against the logging library, in your Android.mk file:
Ohh.. forgot .. The output will be shown in
Logcatwith tagLOG_TAGEasy Approach
Add the following lines to your common header file.
Now just call
LOGD("Hello world") or LOGE("Number = %d", any_int)likeprintf in c.Don’t forget to include the common header file.
Remove the logging
If you define
LOGD(...)empty, all logs will be gone. Just comment afterLOGD(...).#define LOGD(...) // __android_log..... rest of the code