Android JNI配置CMakeLists.txt修改.cpp在logcat打印日志

Android JNI配置CMakeLists.txt修改.cpp在logcat打印日志

C/C++代码里面常用的printf没法在Android 的logcat输出显示。需要特别配置C++才能显示在logcat里面。

(1)CMakeLists.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 )
target_link_libraries( # Specifies the target library.
        application #自己的库

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

(2).cpp中:

#include <string>
#include <android/log.h>

const char *TAG="fly";

#define LOG __android_log_print

void LOGI(const char *info, const char *c) {
    std::string str = info;
    LOG(ANDROID_LOG_INFO, TAG, str.append("%s").c_str(), c);
}

void LOGI(const char *info, int num) {
    LOGI(info, std::to_string(num).c_str());
}

void LOGI(const char *info) {
    LOG(ANDROID_LOG_INFO, TAG, "%s", info);
}

Android添加C++/CPP项目代码(2)_zhangphil的博客-CSDN博客基于Windows平台,Android NDK(JNI)开发技术》【摘要】本文介绍如何基于Windows平台,在Eclipse中使用Android NDK技术实现“Android平台上的JNI ( Java Native Interface ) ”开发。新增的getStringCpp()是新增的一个方法,因为没有实现所以报红。以上完成后,就可以在Java层像使用普通Java函数一样使用getStringCpp()其中,loadLibrary()里面填写的即是(2)里面的xxx.cpp的xxx名字。https://blog.csdn.net/zhangphil/article/details/130207425

Android导入第三方SO库,上层Java调用(1)_zhangphil的博客-CSDN博客(3)把第三方的.so库文件放到\app\libs下。需要注意的,现在一般是64位的so库,如果app\libs下没有\arm64-v8a文件夹,需要新建arm64-v8a目录文件,然后把64位的so库放到。(2)在module的路径下,比如app\下,如果有app\libs目录,不需新建,如果没有,在app\下,新建libs,形成\app\libs目录。Android NDK(JNI)开发_ndk-r10e 版本对应什么sdk_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/130204631

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/130423157