在c代码中进行排错,需要通过使用logca
1、在Android.mk文件中增加配置信息:
LOCAL_LDLIBS += -llog
其中:-l :代表库
2、在C代码中增加头信息:
#include <android/log.h>
#define LOG_TAG "System.out"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
3、使用:
如:DataPass中
//Java把字符串传递给c,c处理后还给java
JNIEXPORT jstring JNICALL Java_com_itheima_datapass_MainActivity_sayHelloInC(
JNIEnv * env, jobject obj, jstring jstr) {
LOGI("hello");
//需要先将java的字符串转换成c字符串
char* cstr = Jstring2CStr(env, jstr);
//加工,添加一些新的c字符串
char* newCStr = " hellos ";
LOGI("newCStr %s\n", newCStr);
//字符串拼接,使用字符串拼接函数
strcat(cstr, newCStr);
LOGI("cstr %s\n", cstr);
//将c字符串转换为java字符串
return (**env).NewStringUTF(env, cstr);
}