一、新建Native C++工程


新建Native C++工程
二、Android Studio已经给搭好了Java调用C++文件的方法,如图:

MainActivity

cpp文件及cmake文件
三、添加cpp方法

新建一个cpplib.cpp

cpplib.cpp写入代码

将新写的cpplib.cpp加到cmake中去

在原来的native-lib.cpp中调用新增函数

运行结果
四、添加第三方库
1、新建thirdlib,假设这是第三方厂商提供的库

新建thirdlib
2、新建thirdlib.cpp、thirdlib.h、CMakeLise.txt【注意,如第三库提供的直接是库文件,而不是源码,则省略这步】

thirdlib

thirdlib.h

thirdlib.cpp

CMakeList.txt
3、改写原有的cpplib.cpp和CMakeList.txt

改写的cpplib.cpp

改写的CMakeList.txt
4、运行结果

运行结果