Dec 04

Creating the android and application make files

Creating the android and application make files



Theoretical background:



The Application.mk is a Make File that defines general variables about how to compile your applications.

For example:

Which ABIs the application will build for, which toolchain and which compiler to use, what is the min android version to build to and cpp flags for the compiler.

An Application can have more than one Application.mk.



The Android.mk file set which c++ sources to build, which header files to link, it defines how to group the source files to shared libraries and static libraries, and defines these libraries relations. It is used to define specific variables and build operations that the Application.mk did not define.

An Application can have more than one Android.mk.


Now let us create our Application.mk and Android.mk file.

We will place them in the app/jni folder:


1. Create a custom Android.mk file and a custom Application.mk file in the app/jni folder of our project:




# We will use the clang compiler

# The ABIs we will build for
APP_ABI := x86 armeabi-v7a

# The Android default C++ runtime support library is libstdc++, however, this library provides a very minimal support and does not include
# for example, the c++ Exceptions and RTTI support.
# Since we will need these implementations, we set here that we will use a different c++ runtime support library - gnustl_shared
# We use the shared version of gnustl and not the gnustl_static version because if we have many modules it is recommended to used the shared
# Otherwise the c++ runtime implementation gnustl_static will be copied to each module and that could cause bugs.
# See https://developer.android.com/ndk/guides/cpp-support.html#runtimes for more details
APP_STL := gnustl_shared

# The platform on which we will build against - its the same as the minSdkVersion defined in the build.gradle file 
APP_PLATFORM := android-19

# Adding the CPP flags 
APP_CPPFLAGS := -std=c++11 -frtti -fexceptions




# A fix for 'abspath' function on Windows platform
# See: http://gnu-make.2324884.n4.nabble.com/using-realpath-abspath-in-3-81-tp13798p13801.html
myabspath = $(join $(filter %:,$(subst :,: ,$1)),$(abspath $(filter-out %:,$(subst :,: ,$1))))

# Common definitions

LOCAL_PATH := $(call my-dir)

# Define a variable for the root of our repository
CROSS_PLATFORM_PROJECT_EXAMPLE_ROOT := $(call myabspath,$(LOCAL_PATH)/../../../..)

# Define other useful path variables

# Note: This path can not be too long, this is already the max length for the path, it won't compile if it is too long

# Our shared library

include $(CLEAR_VARS)

# The name of our shared library module (without the lib preface that is automatically added)
LOCAL_MODULE    := CrossPlatformProjectExample

# Our PCH file

# Flag to indicate that we use a PCH file

# The path to all the header files we use in the project

# All the c++ src files we want to compile

# This is important ! we also need to compile the SWIG generated c++ JNI classes

# Adding required standard libs
# A Documentation about the list of standard libs can be found here: https://developer.android.com/ndk/guides/stable_apis.html
# The list of standard libs are found in <ndk_path>\platforms\<android_version>\<platform_abi>\usr\lib

# The Android Logger



In the next article we will see how to integrate these make files to our Android gradle build system.


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>