Application.mk file syntax specification

Introduction:

This document describes the syntax of Application.mk build files written to describe the native modules required by your Android application. To understand what follows, it is assumed that you have read the OVERVIEW file that explains their role and usage.

Readers of this document should have read OVERVIEW and ANDROID-MK.

Overview:

The purpose of Application.mk is to describe which native 'modules' (i.e. static/shared libraries) are needed by your application.

An Application.mk file is usually placed under $PROJECT/jni/Application.mk, where $PROJECT points to your application's project directory.

Another alternative is to place it under a sub-directory of the top-level $NDK/apps directory, e.g.:

      $NDK/apps/<myapp>/`Application.mk`

Where is a short name used to describe your 'application' to the NDK build system (this name doesn't go into your generated shared libraries or your final packages).

The Application.mk is really a tiny GNU Makefile fragment that must define a few variables:


APP_PROJECT_PATH

This variable should give the absolute path to your Application's project root directory. This is used to copy/install stripped versions of the generated JNI shared libraries to a specific location known to the APK-generating tools.

Note that it is optional for $PROJECT/jni/Application.mk, but mandatory for $NDK/apps/<myapp>/Application.mk


APP_MODULES

If this variable is defined, it tells ndk-build to only list the corresponding modules and those that they depend on. It must be a space-separated list of module names as they appear in theLOCAL_MODULE definition of Android.mk files.

It the variable is undefined, ndk-build looks for the list of all installable top-level modules, i.e. those listed by your Android.mk and any file it includes directly. Imported modules are not top-level though.

An installable module is either a shared library or executable, which will generate a file in libs/$ABI/.

If the variable is undefined, and there are no installable top-level modules in your project, then ndk-build will build all top-level static libraries and their dependencies instead. However, these libraries will be placed at the usual location under obj/ or obj-debug/.

NOTE: This variable's behaviour changed in NDK r4. Before that:

 - the variable was mandatory in your `Application.mk`
- all required modules had to be listed explicitly.

APP_OPTIM

This optional variable can be defined to either 'release' or 'debug'. This is used to alter the optimization level when building your application's modules.

A 'release' mode is the default, and will generate highly optimized binaries. The 'debug' mode will generate un-optimized binaries which are much easier to debug.

Note that if your application is debuggable (i.e. if your manifest sets the android:debuggable attribute to "true" in its <application> tag), the default will be 'debug' instead of 'release'. This can be overridden by setting APP_OPTIM to 'release'.

Note that it is possible to debug both 'release' and 'debug' binaries, but the 'release' builds tend to provide less information during debugging sessions: some variables are optimized out and can't be inspected, code re-ordering can make stepping through the code difficult, stack traces may not be reliable, etc...


APP_CFLAGS

A set of C compiler flags passed when compiling any C or C++ source code of any of the modules. This can be used to change the build of a given module depending on the application that needs it, instead of modifying the Android.mk file itself.

    IMPORTANT WARNING: +++++++++++++++++++++++++++++++++++++++++++++++++++
+
+ All paths in these flags should be relative to the top-level NDK
+ directory. For example, if you have the following setup:
+
+ sources/foo/Android.mk
+ sources/bar/Android.mk
+
+ To specify in foo/Android.mk that you want to add the path to the
+ 'bar' sources during compilation, you should use:
+
+ APP_CFLAGS += -Isources/bar
+
+ Or alternatively:
+
+ APP_CFLAGS += -I$(LOCAL_PATH)/../bar
+
+ Using '-I../bar' will *NOT* work since it will be equivalent to
+ '-I$NDK_ROOT/../bar' instead.
+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

NOTE: In android-ndk-1.5_r1, this only applied to C sources, not C++ ones. This has been corrected to match the full Android build system.


APP_CXXFLAGS

An alias for APP_CPPFLAGS, to be considered obsolete as it may disappear in a future release of the NDK.


APP_CPPFLAGS

A set of C++ compiler flags passed when building C++ sources only.

NOTE: In android-ndk-1.5_r1, this applied to both C and C++ sources. This has been corrected to match the full Android build system. You can now use APP_CFLAGS for flags that shall apply to C and C++ sources.


APP_LDFLAGS

A set of linker flags passed when linking application. This only applies when building shared libraries and executables, these flags are ignored when building static libraries.


APP_BUILD_SCRIPT

By default, the NDK build system will look for a file named Android.mk under $(APP_PROJECT_PATH)/jni, i.e. for the file:

        $(APP_PROJECT_PATH)/jni/Android.mk

If you want to override this behaviour, you can define APP_BUILD_SCRIPT to point to an alternate build script. A non-absolute path will always be interpreted as relative to the NDK's top-level directory.


APP_ABI

By default, the NDK build system will generate machine code for the 'armeabi' ABI. This corresponds to an ARMv5TE based CPU with software floating point operations. You can use APP_ABIto select a different ABI.

For example, to support hardware FPU instructions on ARMv7 based devices, use:

          APP_ABI := armeabi-v7a

Or to support the IA-32 instruction set, use:

          APP_ABI := x86

Or to support the MIPS instruction set, use:

          APP_ABI := mips

Or to support all at the same time, use:

          APP_ABI := armeabi armeabi-v7a x86 mips

Or even better, since NDK r7, you can also use the special value 'all' which means "all ABIs supported by this NDK release":

          APP_ABI := all

For the list of all supported ABIs and details about their usage and limitations, please read CPU-ARCH-ABIS.


APP_PLATFORM

Name the target Android platform. For example, 'android-3' correspond to Android 1.5 system images. For a complete list of platform names and corresponding Android system images, readSTABLE-APIS.


APP_STL

By default, the NDK build system provides C++ headers for the minimal C++ runtime library (/system/lib/libstdc++.so) provided by the Android system.

However, the NDK comes with alternative C++ implementations that you can use or link to in your own applications. Define APP_STL to select one of them. Examples are:

        APP_STL := stlport_static    --> static STLport library
APP_STL := stlport_shared --> shared STLport library
APP_STL := system --> default C++ runtime library

For more information on the subject, please read CPLUSPLUS-SUPPORT.


APP_GNUSTL_FORCE_CPP_FEATURES

In prior NDK versions, the simple fact of using the GNU libstdc++ runtime (i.e. by setting APP_STL to either 'gnustl_static' or 'gnustl_shared') enforced the support for exceptions and RTTI in all generated machine code. This could be problematic in specific, but rare, cases, and also generated un-necessarily bigger code for projects that don't require these features.

This bug was fixed in NDK r7b, but this means that if your code requires exceptions or RTTI, it should now explicitly say so, either in your APP_CPPFLAGS, or your LOCAL_CPPFLAGS /LOCAL_CPP_FEATURES definitions.

To make it easier to port projects to NDK r7b and later, one can optionally defined APP_GNUSTL_CPP_FEATURES to contain one or more of the following values:

        exceptions    -> to enforce exceptions support for all modules.
rtti -> to enforce rtti support for all modules.

For example, to get the exact same behaviour than NDK r7:

        APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti

IMPORTANT: This variable is provided here as a convenience to make it easier to transition to a newer version of the NDK. It will be removed in a future revision. We thus encourage all developers to modify the module definitions properly instead of relying on it here.


APP_SHORT_COMMANDS

The equivalent of LOCAL_SHORT_COMMANDS for your whole project. See the documentation for this variable in ANDROID-MK.


NDK_TOOLCHAIN_VERSION

Define this variable to either 4.4.3 or 4.6 to select version of GCC compiler. 4.6 is the default


APP_PIE

Starting from Jelly Bean (4.1), Android's dynamic linker supports position-independent executables (PIE), which are built with -fPIE. This flag makes it harder to exploit memory corruption bugs by randomization the location of the code. By default, ndk-build will automatically set this value to 'true' if your project targets android-16 or higher. You may set it manually to either 'true' or 'false'.

IMPORTANT: PIE executables cannot run on Android releases prior to 4.1.

Note that this only applies to executables. It has no effect when building shared or static libraries.


APP_THIN_ARCHIVE

Sets the default value of LOCAL_THIN_ARCHIVE for all static library modules in this project. For more information, see the documentation for LOCAL_THIN_ARCHIVE in ANDROID-MK.


A trivial Application.mk file would be:

      -------------- cut here -------------------------
APP_PROJECT_PATH := <path to project>
-------------- cut here -------------------------

Android NDK 学习之Application.mk的更多相关文章

  1. Android NDK开发指南---Application.mk文件和android.mk文件

    https://android.googlesource.com/platform/development/+/donut-release/ndk/docs/OVERVIEW.TXT https:// ...

  2. Android NDK学习(二):编译脚本语法Android.mk和Application.mk

    一.Android.mk Android.mk分为一下几部分: LOCAL_PATH:= $(call my-dir), 返回当前文件在系统中的路径,Android.mk文件开始时必须定义该变量. i ...

  3. Android NDK 学习之Android.mk

    Android.mk file syntax specification Introduction: This document describes the syntax of Android.mk  ...

  4. Android NDK 学习之传递类对象

    本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...

  5. NDK开发之Application.mk文件详解

    做过NDK开发的同学应该都知道有个Application.mk文件,这是android NDK构建系统使用的一个可选构建文件.它的目的是描述应用程序需要哪些模块,也定义了所有模块的一些通用变量.主要有 ...

  6. Android NDK学习记录(一)

    一.NDK环境在Mac中部署 1.准备eclipse,android sdk安装包,android ndk安装包(http://dl.google.com/android/ndk/android-nd ...

  7. Android NDK 学习之在C中抛出异常

    本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...

  8. Android NDK 学习之调用Java函数

    本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...

  9. Android NDK 学习之在C中调用Java的变量和静态变量

    本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...

随机推荐

  1. 品优购商城项目(二)AngularJS、自动代码生成器、select2下拉多选框

    品优购商城想项目第二阶段 AngularJS.自动代码生成器.select2下拉多选框 完成了课程第三天.第四天的的任务. 1.学习了AngularJs前端的mvc分层思想,js部分分成control ...

  2. IFC构件位置数据与revit模型中对应构件位置数据对比

    IFC构件位置数据与revit模型中对应构件位置数据对比

  3. linux非root用户安装rabbitmq

    因为rabbitmq是用erlang语言写的,所以装rabbitmq前第一步得先装erlang. 我们到erlang官网https://www.erlang.org/downloads下载安装包,最新 ...

  4. Python subprocess中的run方法

    调用subprocess的推荐方法是对于它可以处理的所有使用场景都使用run()函数. run()函数是在Python 3.5中添加的,如果在老版本中使用,需要下载并扩展. 扩展安装方式: $ pip ...

  5. Elasticsearch - 处理冲突

    http://blog.csdn.net/xifeijian/article/details/49615559

  6. ECOC 2019展会:以太网联盟公开展示其下一代网络100/200/400G互通测试能力,网络自动化测试能力再次被提出

    欧洲光纤通讯展ECOC 2019正在火热进行,以太网联盟组织Ethernet Alliance在其公开展台演示了其下一代高速网络100G/200G/400G相关能力,其成员单位Cisco,Arista ...

  7. Java基础:类文件结构及类加载

    Class文件结构 魔数 4bits 确定该文件是否是可接受的Class文件(0xCAFEBABE) 版本号 4bits 包括次版本号和主版本号 常量池 包括字面量(文本字符串,声明为final的常量 ...

  8. 集合运算 & 聚合函数

    SQL 查询之集合运算 & 聚合函数   1.集合运算 1.1.并集运算 UNION 1.2.差集运算 EXCEPT 1.3.交集运算 INTERSECT 1.4.集合运算小结 2.聚合函数 ...

  9. IDEA中的,让光标回到上一次停留的地方

    IDEA中的,光标返回到上一次停留的地方ctrl+alt+ ←IDEA中的,光标返回到下一次停留的地方ctrl+alt+ → 不过要小心,笔记本电脑,默认的翻转屏幕的快捷键和这个冲突..我的选择是关闭 ...

  10. 洛谷 题解 P1550 【[USACO08OCT]打井Watering Hole】

    本题看似很难,实际上思路非常简单--如果你想通了. 首先有一个问题:图中有几个点?大部分的人会回答\(n\)个点.错了,有\(n+1\)个. 多出来的那个点在哪?关键在于你要理解每一个决策的意义.实际 ...