Android NDK:CMAKE如何将导入的共享库移动到libs文件夹

时间:2019-01-24 19:28:41

标签: android cmake android-ndk android-gradle

我有一个构建get_initial()的Android NDK项目,并且正在使用:

libMyProject1.so

将构建的库导出到我需要的文件夹中。

我还有另一个与之链接的外部共享库:

我的外部图书馆

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

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,但是Client/libs/${ANDROID_ABI}没有被复制。如何使用cmake将外部共享库复制到我的客户端文件夹?

2 个答案:

答案 0 :(得分:1)

如评论中所建议,以下对我有用:

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../MyExternal/libs/${ANDROID_ABI}/libMyExternal.so
        DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../Client/libs/${ANDROID_ABI})

答案 1 :(得分:0)

您应该更改 jniLibs.srcDirs ,它将由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 {
   ...
}