我们可以在c/cpp代码中用 print 函数输出log信息,但是这样在 logcat并 不会显示,好在 Android 已经给我提供了相应的方法解决这个问题:使用 log.h 头文件
开始
创建一个新的Android Studio的工程项目
勾选 Include C++ support 选项
然后就是一路next直到创建项目成功
项目结构
生成好的项目会在 main 目录下创建好 cpp 目录和相应的cpp文件,以及 CmakeLists 文件
CmakeLists
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# 限定cmake支持最低版本
cmake_minimum_required(VERSION 3.4.1)
# 指定so生成到libs目录
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/libs/${ANDROID_ABI})
# 配置so库的信息
add_library( # Sets the name of the library.
# 生成的so库名称,并不需要和c/cpp文件名相同
#