jni开发-CmakeList详解

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/u013470102/article/details/89841331

下面是项目中的so的CmakeList配置和注意事项:

# 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)
#set so created path
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/jniLibs/${ANDROID_ABI})
# 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 the name of the library.
            audiooperate     #so的文件名
# Sets the library as a shared library.
             SHARED
# Provides a relative path to your source file(s).
${CMAKE_SOURCE_DIR}/src/main/cpp/audiooperate-lib.cpp  #项目中使用的c或c++文件,一定要仔细检查路径对不对
${CMAKE_SOURCE_DIR}/src/main/cpp/decode/Decode_WAVE.cpp
${CMAKE_SOURCE_DIR}/src/main/cpp/resample/fa_fir.c
${CMAKE_SOURCE_DIR}/src/main/cpp/resample/fa_resample.c
${CMAKE_SOURCE_DIR}/src/main/cpp/resample/getopt.c
${CMAKE_SOURCE_DIR}/src/main/cpp/resample/start.c
${CMAKE_SOURCE_DIR}/src/main/cpp/mixer/mixer.cpp
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/basic_op/basicop2.c       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/basic_op/oper_32b.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/aac_rom.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/aacenc.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/aacenc_core.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/adj_thr.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/band_nrg.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/bit_cnt.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/bitbuffer.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/bitenc.c                     ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/block_switch.c                     ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/channel_map.c                     ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/cmnMemory.c                  ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/dyn_bits.c              ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/grp_data.c                         ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/interface.c                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/line_pe.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/memalign.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/ms_stereo.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/pre_echo_control.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/psy_configuration.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/psy_main.c                      ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/qc_main.c                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/quantize.c                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/sf_estim.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/spreading.c                       ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/stat_bits.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/tns.c
${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/transform.c                      ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV5E/AutoCorrelation_v5.s                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV5E/band_nrg_v5.s                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV5E/CalcWindowEnergy_v5.s                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV7/PrePostMDCT_v7.s                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV7/R4R8First_v7.s                        ${CMAKE_SOURCE_DIR}/src/main/cpp/aacenc/src/asm/ARMV7/Radix4FFT_v7.s
 )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
                       audiooperate   #so的文件名对应
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

这个是比较简单的配置方式。

下面看一下配置ffmpeg下库的so的配置

cmake_minimum_required(VERSION 3.4.1)
set(lib_src_DIR ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI})
include_directories(
        ${CMAKE_SOURCE_DIR}/src/main/cpp/include
)

add_library( native-lib
             SHARED
             src/main/cpp/native-lib.cpp
              src/main/cpp/suplayer/player.cpp
               src/main/cpp/suplayer/queue.c
            )

add_library(avcodec-57_lib SHARED IMPORTED)
set_target_properties(avcodec-57_lib PROPERTIES IMPORTED_LOCATION
                             ${lib_src_DIR}/libavcodec-57.so)


add_library(avformat-57_lib SHARED IMPORTED)
set_target_properties(avformat-57_lib PROPERTIES IMPORTED_LOCATION
                        ${lib_src_DIR}/libavformat-57.so)

add_library(avutil-55_lib SHARED IMPORTED)
set_target_properties(avutil-55_lib PROPERTIES IMPORTED_LOCATION
                        ${lib_src_DIR}/libavutil-55.so)

add_library(swresample-2_lib SHARED IMPORTED)
set_target_properties(swresample-2_lib PROPERTIES IMPORTED_LOCATION
                        ${lib_src_DIR}/libswresample-2.so)

add_library(swscale-4_lib SHARED IMPORTED)
set_target_properties(swscale-4_lib PROPERTIES IMPORTED_LOCATION
                        ${lib_src_DIR}/libswscale-4.so)

add_library(libyuv SHARED IMPORTED)
set_target_properties(libyuv PROPERTIES IMPORTED_LOCATION
                        ${lib_src_DIR}/libyuv.so)


set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

target_link_libraries( native-lib
                       log
                       Threads::Threads
                       android
                       OpenSLES
                       avcodec-57_lib
                       avformat-57_lib
                       avutil-55_lib
                       swresample-2_lib
                       swscale-4_lib
                       libyuv
                        )

猜你喜欢

转载自blog.csdn.net/u013470102/article/details/89841331