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
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'
}
}
}