Android studio 2.2版本以后对C/C++的支持可以说很方便了,当然官方推荐使用Cmake完成对C/C++的支持
2.2版本以上的同学新建一个项目就知道了,步骤如下:
File -> New -> New Project,如下图:
然后勾选Include C++ support,一直next ,最后Finish以后,项目就出现了,和一般的项目略有不同,其实只要多了几个文件,而已:
1:目录下多了个CmakeLists.txt文件
2:src目录下多了一个cpp目录,里面有个.cpp文件,C++文件都是以.cpp结尾的。
3:就是build.gradle内容中添加了几行配置
一一解读一下,先来看看CmakeLists.txt 文件里面的内容是什么:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets th