Copy shared objects to jniLibs when using cmake for Android

后端 未结 1 544
深忆病人
深忆病人 2021-01-03 09:51

I have recently started to move my Android build from Ant to Gradle and then I want to use cmake for my C++ code. The build is currently running fine, but no shared objects

相关标签:
1条回答
  • 2021-01-03 10:37

    I figured out how to do it in the end. To include built shared objects from some place we need to use sourceSets.main.jniLibs.srcDirs inside the android part of our build.gradle. The example below fetches is directly from the Android cmake output directory for shared objects (for debug).

    For example:

    android {
        ...
        defaultConfig {
            ...
        }
    
        buildTypes {
            release {
            }
            debug {
            }
        }
    
        sourceSets {
            main {
                // Bundle so files with the final apk.
                // NOTE: Currently bundles all shared objects in that directory.
                // It was not straightforward to exclude in Android sourceSets at the time of writing,
                // see https://code.google.com/p/android/issues/detail?id=64957
                jniLibs.srcDirs = ['.externalNativeBuild/cmake/debug/libs']
            }
        }
    
        externalNativeBuild {
            cmake {
                path '../../../CMakeLists.txt'
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题