1. 创建一个新的project,一定要勾选“include C++ support”
注: 项目默认是用的是CMake,并不会自动生成Android.mk
2. 创建完毕后,会在src/main/下创建cpp和java目录,cpp对应native代码, java就不用说了
3. 在cpp目录下新建Android.mk
示例代码如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopus_jni
LOCAL_SRC_FILES := native-lib.cpp
include $(BUILD_SHARED_LIBRARY)
4. 修改build.gradle文件,设置使用ndk-build,而不是cmake
defaultConfig {
...
externalNativeBuild {
ndk {
ldLibs "log"
abiFilters "armeabi", "armeabi-v7a", "x86", "x86_64", "mips"
}
}
}
...
externalNativeBuild {
ndkBuild {
path "src/main/cpp/Android.mk"
}
}
5. 如果要使用C++的库,则创建Application.mk文件,添加如下代码
APP_STL := stlport_static