Android NDK Development Guide --- Application. mk File

Source: Internet
Author: User

Introduction:
-----------------------------
To compile C \ C ++ code into a SO file, you still need an Application. mk file.
This document describes how to use the Application. mk syntax of the local module required by your Android Application.

Application. mk is used to describe the modules required in your Application (static or dynamic library ).

The Application. mk file is usually placed under $ PROJECT/jni/Application. mk. $ PROJECT refers to your PROJECT.

Another method is to place it in the subdirectory at the top level:
$ NDK/apps directory, for example:
$ NDK/apps/<myapp>/Application. mk

<Myapp> is short for describing the application of your NDK compilation system (this name does not generate a shared library or the final package)

The following are the variables defined in Application. mk.

APP_PROJECT_PATH
This variable is mandatory and gives an absolute path to the root directory of the application project. This is used to copy or install a JNI library without any version restrictions, so as to provide a detailed path for the APK generation tool.

APP_MODULES
This variable is optional. If not defined, NDK is compiled by the default module declared in Android. mk and contains all the sub-files (makefile files)
If APP_MODULES is defined, it cannot be a list of modules separated by spaces. The module name is defined in LOCAL_MODULE In the Android. mk file. Note that the NDK automatically calculates the module dependency.

Note: NDK changes the behavior of this variable in R4. Before the change:
-In your Application. mk, this variable is mandatory.
-All required modules must be explicitly listed.

APP_OPTIM
This variable is optional and is used to define "release" or "debug ". When compiling your application module, it can be used to change the priority.

The "release" mode is default and highly optimized binary code is generated. The "debug" Mode generates unoptimized binary code, but many bugs can be detected and used for debugging.

NOTE: If your application is debuggable (that is, if android: debuggable is set to "true" in your configuration file "). The default value is "debug" rather than "release ". This can be overwritten by setting APP_OPTIM to "release.

Note: Debugging can be performed in the "release" and "debug" modes. However, after compiling in the "release" mode, fewer BUG information is provided. When we know the BUG, some variables are optimized or cannot be detected at all. The code re-sorting will make these variables more difficult to read, and make these tracks more unreliable.

APP_CFLAGS
When the compilation module contains any C file or C ++ file, the C compiler signal is sent. Here, you can adjust the Compilation When you need these modules in your application. In this way, you are not allowed to directly change Android. mk to the file itself.

Important warning: ++ ++
+
+ In these compilation, all paths must correspond to the top-level NDK directory.
+ For example, if you have the following settings:
+
+ Sources/foo/Android. mk
+ Sources/bar/Android. mk
+ During compilation, to specify the path you want to add to the bar source code in foo/Android. mk,
+ You should use
+ APP_CFLAGS + =-Isources/bar
+ Or alternate:
+ APP_CFLAGS + =-I $ (LOCAL_PATH)/../bar
+
+ Using '-l ../bar/' won't work, thinking it will be equivalent to "-l $ NDK_ROOT/../bar"
++ ++
Note: Android NDK 1.5_r1 only applies to C source files, not C ++.
This has been corrected to build a completely matched Android system.

APP_CXXFLAGS
APP_CPPFLAGS alias, which has been considered to be removed in future versions

APP_CPPFLAGS
When only the C ++ source file is compiled, you can use this C ++ compiler to set

Note: In the Android NDK-1.5_r1, this flag can be applied to C and C ++ source files. In addition, it is corrected to build a complete Android compilation system that matches the system. You can also use APP_CFLAGS to apply it to C or C ++ source files.
APP_CFLAGS is recommended.

APP_BUILD_SCRIPT
By default, the NDK compilation system searches for the Android. mk file in the $ (APP_PROJECT_PATH)/jni directory:
$ (APP_PROJECT_PATH)/jni/Android. mk

If you want to override this behavior, you can define APP_BUILD_SCRIPT to specify a backup compilation script. A non-absolute path is always interpreted as the top-level directory relative to the NDK.

APP_ABI
By default, the NDK compilation system evict "armeabi" ABI to generate machine code. Which is equivalent to an ARMv5TE that can be used for floating-point operations based on the CPU. You can use APP_ABI to select a different ABI.

For example, to support hardware FPU commands on ARMv7 devices. Available
APP_ABI: = armeabi-v7a

Or to support the IA-32 instruction set, you can use
APP_ABI: = x86

Or you can use
APP_ABI: = armeabi armeabi-v7a x86

APP_STL
By default, the NDK compilation system provides C ++ header files for the minimum C ++ Runtime Library (/system/lib/libstdc ++. so.
However, the implementation of ndk c ++ allows you to use or link to your own applications.
For example:
APP_STL: = stlport_static --> static STLport library
APP_STL: = stlport_shared --> shared STLport library
APP_STL: = system --> default C ++ runtime library

The following is an example of an Application. mk file:
APP_PROJECT_PATH: = <path to project>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.