To track the log in Android native project.
- run the android virtual machine using eclipse
- open terminal
- go to the specific folder
- command adt logcat to view the log information (This will only run while your android virtual machine is running ,if not it will giving a message like bellow)
Dhanushanths-MacBook-Pro:RFIDIntegration dhanus$ adb logcat
- waiting for device -
From Java
First we see how to pass log information form Java,
Pass the log data information from Java to adb log cat is pretty simple
package test.rfid.integration;
import android.util.Log;------------------------(1)
public class RfidLib {
//Write a own lines in Log using terminal
public static final String TAG = "Test"; ------------(2)
public static int addValueJ(int x,int y){
Log.d(TAG,"*********The log data from the Java Method************");-----(3)
int sum = x+y;
return sum;
}
public native static int addValueN(int x,int y);
static{
System.loadLibrary("test_rfid_integration_RfidLib");
}
}
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test_rfid_integration_RfidLib.c
LOCAL_MODULE := test_rfid_integration_RfidLib
LOCAL_LDLIBS := -llog ---------------(make line)
include $(BUILD_SHARED_LIBRARY)
From Native
Here we can call the log from native code,
#include "test_rfid_integration_RfidLib.h"
#include <android/log.h> ----------------(1)
/*
* Class: test_rfid_integration_RfidLib
* Method: addValueN
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_test_rfid_integration_RfidLib_addValueN
(JNIEnv *env, jclass cla, jint x, jint y)
{
//pass the log data in to terminal using
__android_log_print(ANDROID_LOG_DEBUG, "test_rfid_integration_Rfidlib.c", "*********Log data from Native code***********"); ----------(2)
jint sum = x * y;
return sum;
}
Add the two lines which are mentioned in bellow as 1 and 2.
Finally to build the file use ,
- ndk-build clean
- ndk-build all
great you are in business
No comments:
Post a Comment