Android - NDK:在Jni中打印Log信息

在Jni中打印Log信息

1、在配置CMakeLists.txt

txt 复制代码
find_library( # Sets the name of the path variable.
        log-lib
        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        ndktest
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

2、在jni层的cpp文件中定义

c 复制代码
#include <android/log.h>

#define LOG_TAG "MyJNILog"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG ,__VA_ARGS__) // 定义LOGI类型
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG ,__VA_ARGS__) // 定义LOGD类型
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG ,__VA_ARGS__) // 定义LOGW类型
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG ,__VA_ARGS__) // 定义LOGE类型
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,LOG_TAG ,__VA_ARGS__) // 定义LOGF类型

3、在jni中使用

复制代码
LOGI("strPre = %s", buf);  // 输出字符串

LOGI("in native , a = %f,b= %f", a, b);  // a和b为double类型或float类型

LOGI("len1 = %d, len2 = %d", len1, len2);  // 输出int类型
相关推荐
new_bie_B2 小时前
Android16 Input 事件分发链路
android
TDengine (老段)4 小时前
TDengine RAFT共识协议 — 选举、日志复制、快照与仲裁
android·大数据·数据库·物联网·架构·时序数据库·tdengine
YF02117 小时前
深入剖析 Kotlin 的高效之道与核心实战
android·kotlin·app
程序员码歌8 小时前
别再让 AI 自由发挥了:OpenSpec 才是团队协作不跑偏的关键
android·前端·人工智能
敲代码的鱼8 小时前
NFC读卡能力 支持安卓/iOS/鸿蒙 UTS插件
android·ios·uni-app
刮风那天9 小时前
Android 常驻进程如何被查杀?
android
刮风那天10 小时前
Android 如何降低进程优先级可以被查杀?
android
资源分享助手12 小时前
超级改图P图改字无限制版教程(安卓)AI改图软件、图片改字软件、安卓修图APP、智能消除工具、图片拼接APP、超级改图下载
android·人工智能
Lehjy12 小时前
【Linux】文件系统磁盘存储结构
android·linux·运维
BU摆烂会噶13 小时前
【LangGraph】节点内调用与状态隔离
android·人工智能·python·ui·langchain·人机交互