2

I have an Android NDK project which builds libMyProject1.so and I am using:

set_target_properties(MyProject1 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../Client/libs/${ANDROID_ABI}") 

to export the built library to the folder that I need.

I also have another external shared library that I link with:

MyExternal library

add_library(MyExternal SHARED IMPORTED) set_target_properties(MyExternal PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../MyExternal/libs/${ANDROID_ABI}/libMyExternal.so) target_link_libraries( # Specifies the target library. MyProject1 # Shared Dependencies MyExternal # Links the target library to the log library # included in the NDK. ${log-lib}) 

libMyProject1.so is copied to Client/libs/${ANDROID_ABI} but libMyExternal.so is not copied. How to copy the external shared library to my client folder using cmake?

2
  • 2
    Property LIBRARY_OUTPUT_DIRECTORY affects only on the library produced by your project. It doesn't affect on IMPORTED libraries which have already exist. You need to copy such library manually. Choose any way described in that question: stackoverflow.com/questions/34799916/…. Commented Jan 24, 2019 at 19:44
  • thanks @Tsyvarev, file(COPY ... ) worked. Commented Jan 24, 2019 at 20:05

2 Answers 2

1

As suggested in the comments, the following worked for me:

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../MyExternal/libs/${ANDROID_ABI}/libMyExternal.so DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../Client/libs/${ANDROID_ABI}) 
Sign up to request clarification or add additional context in comments.

Comments

0

You should change the jniLibs.srcDirs, which will be packed by the gradle.

apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { ... ndk { abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' } ... } ... sourceSets { main { // let gradle pack the shared library into apk jniLibs.srcDirs = ['Client/libs/'] } } externalNativeBuild { cmake { path "CMakeLists.txt" } } } dependencies { ... } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.