简体   繁体   中英

How to add external library in android studio with cmake?

I am trying to link live555.so and .h files with an Android project using cMake. If i don't use absolute path i'm getting error.

My cMake file:

cmake_minimum_required(VERSION 3.4.1)

include_directories( ${PROJECT_SOURCE_DIR}/src/main/jniLibs/live555/include )

add_library( live555 SHARED IMPORTED )

set_target_properties( live555 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/jniLibs/live555/lib/${ANDROID_ABI}/live555.so)

add_library( # Sets the name of the library.
         native-lib

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         src/main/cpp/native-lib.cpp )

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 )

target_link_libraries( # Specifies the target library.
                   native-lib
                   android
                   live555
                   ${log-lib} )

And error :

Error:error: '../../../../src/main/jniLibs/live555/lib/armeabi-v7a/live555.so', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it

${PROJECT_SOURCE_DIR} is the directory where the main CMakeList.txt file resides. That's typically app/src/main/cpp . You can work out the correct relative path now.

This means that you can simply write

include_directories( ${PROJECT_SOURCE_DIR}/../jniLibs/live555/include )

add_library( live555 SHARED IMPORTED )

set_target_properties( live555 PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/../jniLibs/live555/lib/${ANDROID_ABI}/live555.so)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM