ndk中日志,调试及故障处理

ndk中日志,调试及故障处理_第1张图片

ndk中日志,调试及故障处理_第2张图片

ndk中日志,调试及故障处理_第3张图片

下面来一个实际例子  

android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myNativeLib
LOCAL_SRC_FILES :=test_com_myndk2_NdkUtils.cpp
LOCAL_LDLIBS :=-llog
include $(BUILD_SHARED_LIBRARY)

cpp

#include "test_com_myndk2_NdkUtils.h"
 #include 
 #include 
#include 
#include 

#define  LOG_TAG    "hb-4"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

 JNIEXPORT jstring JNICALL Java_test_com_myndk2_NdkUtils_getNativeString (JNIEnv *env, jobject obj,jstring str)
 {
            LOGI("call getNativeString");
           const char* cppStr=env->GetStringUTFChars(str,NULL);
            LOGI("STR=%s",cppStr);
            env->ReleaseStringUTFChars(str,cppStr);
            int var=55;
            LOGI("var=%d",var);
     return env->NewStringUTF("HelloFrom JNI!");
 }
输出日志

01-11 10:50:09.500 30119-30119/test.com.myndk2 I/hb-4: call getNativeString
01-11 10:50:09.500 30119-30119/test.com.myndk2 I/hb-4: STR=java to cpp 你妹的
01-11 10:50:09.500 30119-30119/test.com.myndk2 I/hb-4: var=55
01-11 10:50:09.500 30119-30119/test.com.myndk2 I/hb-4: ndk返回的字符串:HelloFrom JNI!

demo地址:

http://download.csdn.net/detail/hb707934728/9734462

你可能感兴趣的:(ndk)