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类型
相关推荐
超勇的阿杰32 分钟前
gulimall项目笔记:P54三级分类拖拽功能实现
android·笔记
峥嵘life2 小时前
Android 欧盟网络安全EN18031 要求对应的基本表格填写
android·安全·web安全
程序员码歌4 小时前
【零代码AI编程实战】AI灯塔导航-从0到1实现篇
android·前端·人工智能
北十南4 小时前
SODA自然美颜相机(甜盐相机国际版) v9.3.0
android·windows·数码相机
Harry技术4 小时前
Trae搭建Android项目:智能存储柜表结构设计以及实体生成
android·kotlin·trae
编程乐学5 小时前
网络资源模板--基于Android Studio 实现的通讯录App
android·android studio·移动端开发·通讯录app·安卓大作业
bytebeats6 小时前
# Android Studio Narwhal Agent 模式简介
android·android studio
吴Wu涛涛涛涛涛Tao7 小时前
Flutter 实现类似抖音/TikTok 的竖向滑动短视频播放器
android·flutter·ios
bytebeats7 小时前
Jetpack Compose 1.8 新增了 12 个新特性
android·android jetpack
limingade8 小时前
手机实时提取SIM卡打电话的信令声音-整体解决方案规划
android·智能手机·usb蓝牙·手机拦截电话通话声音