android OpenSLES属于jni开发的范畴,虽然在c++层能够直接引用OpenSLES头文件,在代码编写阶段没什么问题,但是如不把OpenSLES库文件配置到NDK编译环境来编译会报错,配置方法跟OpenGL相似:
find_path(SL_INCLUDE_DIR SLES/OpenSLES.h
HINTS ${ANDROID_NDK}) #找到opensl头文件路径
find_library(SL_LIBRARY libOpenSLES.so
HINTS ${SL_INCLUDE_DIR}/../lib) #找到opensl库文件路径
include_directories(
${CMAKE_SOURCE_DIR}/src/main/cpp #此处忽略
${CMAKE_SOURCE_DIR}/libs/include #此处忽略
${SL_INCLUDE_DIR} #把头文件路径添加进来
)
target_link_libraries(
jni-native #此处忽略
${SL_LIBRARY} #把opensl库文件添加进来
${log-lib} #此处忽略
)