(创建于2017/12/28)
已实现
注意几点:
1.main下cpp文件夹放置c文件和相关头文件
2.main下JniLibs文件夹放置第三方so文件
3.app下libs文件夹放置jar包
4.CMakeLists配置文件:
cmake_minimum_required(VERSION 3.4.1)
add_library(
//打包多个cpp文件为同一个so文件qq_voice
qq_voice
SHARED
src/main/cpp/common.cpp
src/main/cpp/play_sound.cpp
src/main/cpp/common_platform.cpp
)
//引入第三方
add_library( libfmod
SHARED
IMPORTED )
//配置第三方路径
set_target_properties( libfmod
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libfmod.so )
//引入第三方
add_library( libfmodL
SHARED
IMPORTED )
//配置第三方路径
set_target_properties( libfmodL
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libfmodL.so )
find_library(
log-lib
log )
target_link_libraries(
qq_voice
libfmod
libfmodL
${log-lib} )
5.build.gradle文件配置
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags ""
}
}
ndk {
//和JniLibs下的api相对应,不然会报错
abiFilters 'armeabi', 'armeabi-v7a','arm64-v8a','x86'
}
}
...
externalNativeBuild {
cmake {
//配置CMakeLists文件路径
path 'CMakeLists.txt'
}
}
}