Gradle NDK to specify the 'include' directive in the created Android.mk

If you

android { defaultConfig { ndk { moduleName "yourlib" stl "stlport_static" ldLibs "log", "z", "m" cFlags "-I/some/include/dir/" } ... } ... } 

in your build.gradle, then Gradle will compile the files in src / main / jni / and it will generate Android.mk in the build / ndk / debug / Android.mk file.

However, in my case, I am trying to compile some C ++ files compiled with OpenCV.

This works for me when I manually create the Android.mk file and run the ndk-build command. But I want to do this through Gradle / Android Studio automatically.

When you do this manually, I include libraries for links. I do this in manually created Android.mk using the line:

 include /path/to/the/opencv/directory/sdk/native/jni/OpenCV.mk 

However, in the Android Gradle plugin, I'm not sure how to add this include directive to the generated Android.mk file.

Can someone point me in the right direction of Gradle-directive to add this line to the file file? Thanks.

+7
android opencv android-ndk gradle
source share
1 answer

I found that the build process will pull everything out from under the folder. / src / main / jni. So, I placed symbolic links there for inclusion and src folders in another place - src files will be listed in the .mk file by the build process, and inc files will be crossed out by the compiler. Perhaps this is a bit of hacks:

 android { defaultConfig { ndk { moduleName "yourlib" cFlags "-std=c99 -I${project.buildDir}/../src/main/jni/inc" } ... } ... } 

I also have different cFlags depending on the debug build. This seems like a valid gradle, but doesn't want to build with android-studio. It will build using the gradlew tho command:

 android { defaultConfig { ndk { moduleName "yourlib" cFlags "-std=c99 -I${project.buildDir}/../src/main/jni/inc" } ... } ... buildTypes { release { debuggable false jniDebugBuild false ndk { moduleName "yourlib" } } debug { debuggable true jniDebugBuild true ndk { moduleName "yourlib" ldLibs "log" cFlags "-g -D_DEBUG" } } } } 

I hope this can help you (android studio 0.8.6).

+8
source share

All Articles