«

»

Dec 04

Building the Android project using Gradle or MakeFiles

Building the Android project using Gradle or MakeFiles

 

 

Theoretical Background:

 

The android build system uses Gradle, and it consists of an android plugin for Gradle.

When we create a project a build.gradle (Module: app) file is created (under the folder app) and auto generated with the plugin:

apply plugin: ‘com.android.application’

This plugin enables us to set the:

android { … }

Element available, and in this element we can set specific build instructions for android, for example setting the compileSdkVersion.

 

Note: There is another build.gradle file under your project root directory, this gradle file is set for build properties related to all your modules, while the build.gradle under the App directory is just for a single module, there can be more than one gradle file and they can take dependency on each other.

 

The android studio build system makes some assumption on the folder structure of your project, if you changed some of the folders structure you will have to change the build.gradle file to match the new folders.

 

There are two ways to compile your native code:

1. Using the built in Gradle support for NDK in Android Studio

2. Using a custom Android.mk and Application.mk

 

Why is it best to use Android.mk and not the built in Gradle in Android Studio?

The Gradle plug-in used by Android Studio to build the project generates an Android.mk file and an Application.mk file on the fly, using the settings we define in the build.script.

The problem is that the current support for NDK applications in Android Studio using Gradle to build, are those consisting of just one shared library module, without any dependencies, without splitting to more than one module. For example, using static and shared libraries dependencies is not enabled, and there are more options missing.

So unless your native code is really a small part of the project and you don’t need much customizations, it is recommended to disable the built it Gradle support to the NDK and use a custom Android.mk file (or files) and Application.mk file.

 
 

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>