Dec 04

Building the Android project using Gradle

Building the Android project using Gradle




To build using Gradle:

If you want to use the android NDK to build C++ code, all you have to do is:

1. In the build.gradle file add under android->defaultConfig the following element:


ndk {
    moduleName "<your_module_name>"
    //You can declare here other lib dependencies your project will use
    ldLibs "log"


2. Create a jni folder: app\src\main\jni. And place your c++ files there.

Once Gradle runs, it checks if the jni folder exists, and if it does it assumes you have cpp files under this folder and it will compile them using the Android NDK, calling ndk-build command.



You can set various ndk build related options in Gradle, using the android.ndk element, for example:


android.ndk {
// All configurations that can be changed in android.ndk.</p>
moduleName = "native"
toolchain = "clang"
toolchainVersion = "3.5"
cppFlags += "-DCUSTOM_DEFINE"
ldFlags += "-L/custom/lib/path"
ldLibs += "log"
stl = "stlport_static"


You can read more about the android plugin for Gradle at the following link:



Good luck !

Leave a Reply

Your email address will not be published.

אתם יכולים להשתמש באפשרויות ותגי ה-HTMLהבאים: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>