Here we specify the path src/main/jniLibs because the libraries from this directory are automatically included in the APK after compiling the project. NDK_LIBS_OUT - the directory in which the libraries will be located after compilation. We also pass an array of arguments for the command in the args property: To do this, we get the path to the installed NDK in the first line and add the name "/ndk-build" to it. We must assign the path to the command to the executable property. Tasks of Exec type are used to run external commands. In the app/adle file we configure the library build via CMake in the usual way: You can view the files in the app/src/main/jni/ directory.
I created a simple project on GitHub with two C libraries: one with a build script CMakeLists.txt and the other built via Android.mk. But I don’t want to run it manually every time, so in this article, we will use Gradle’s ability to invoke external commands and configure ndk-build to run automatically during application build. The most obvious solution would be to use CMake by default and run ndk-build separately.
I will show one of the possible ways to solve this problem. But if you specify two paths to the build scripts CMakeLists.txt and Android.mk in the adle file, then Gradle will show an error “More than one externalNativeBuild path specified” and will not compile anything. You may need to use both build systems at the same time to compile some existing libraries. Android NDK currently provides us with at least two ways to build native libraries: CMake and ndk-build.