Any simple way to log in Android NDK code?

前端 未结 7 2397
無奈伤痛
無奈伤痛 2020-12-02 12:09

I\'m looking for a way to easily debug C code in an Android NDK application using Eclipse. I\'ve read ways to debug the app using gdb or something similar but what I want i

7条回答
  •  孤城傲影
    2020-12-02 12:31

    No one has posted info about different log levels so far. The answer is an attempt to make the logging "picture" full.

    #include 
    
    #define TAG "MY_TAG"
    
    #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,    TAG, __VA_ARGS__)
    #define LOGW(...) __android_log_print(ANDROID_LOG_WARN,     TAG, __VA_ARGS__)
    #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,     TAG, __VA_ARGS__)
    #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,    TAG, __VA_ARGS__)
    

    Usage:

    char err[] = "wrong";
    LOGE("Something went %s", err);
    

    Link Android log library as below.

    Android.mk:

    LOCAL_LDLIBS := -llog
    

    CMakeLists.txt:

    find_library( log-lib log )
    target_link_libraries( ${log-lib} )
    

    Further reading: Logging

提交回复
热议问题