android ndk Application.mk
2015-10-10 12:54
405 查看
Application.mk
On this page
OverviewVariables
This document explains the
Application.mkbuild file, which describes the native modules that your app requires. A module can be a static library, a shared library,
or an executable可执行的.
We recommend that you read the Concepts and Android.mk pages
before this one. Doing so will help maximize your understanding of the material材料 on this page.
Application.mk
Application.mk目的是描述在你的应用程序中所需要的模块(即静态库或动态库)。
变量 | 描述 |
APP_PROJECT_PATH | 这个变量是强制性的,并且会给出应用程序工程的根目录的一个绝对路径。 |
APP_MODULES | 这个变量是可选的,如果没有定义,NDK将由在Android.mk中声明的默认的模块编译,并且包含所有的子文件(makefile文件)如果APP_MODULES定义了,它不许是一个空格分隔的模块列表,这个模块名字被定义在Android.mk文件中的LOCAL_MODULE中。 |
APP_OPTIM | 这个变量是可选的,用来义“release”或"debug"。在编译您的应用程序模块的时候,可以用来改变优先级。 |
APP_CFLAGS | 当编译模块中有任何C文件或者C++文件的时候,C编译器的信号就会被发出。 |
APP_CXXFLAGS | APP_CPPFLAGS的别名,已经考虑在将在未来的版本中废除了 |
APP_CPPFLAGS | 当编译的只有C++源文件的时候,可以通过这个C++编译器来设置 |
APP_BUILD_SCRIPT | 默认情况下,NDK编译系统会在$(APP_PROJECT_PATH)/jni目录下寻找名为Android.mk文件: $(APP_PROJECT_PATH)/jni/Android.mk |
APP_ABI | 默认情况下,NDK的编译系统回味"armeabi"ABI生成机器代码。 |
APP_STL | 默认情况下,NDK的编译系统为最小的C++运行时库(/system/lib/libstdc++.so)提供C++头文件。然而,NDK的C++的实现,可以让你使用或着链接在自己的应用程序中。 例如: APP_STL := stlport_static --> static STLport library APP_STL := stlport_shared --> shared STLport library APP_STL := system --> default C++ runtime library |
|
Overview概述
TheApplication.mkfile is really a tiny GNU Makefile fragment that defines several variables for compilation编译. It usually resides存在 under
$PROJECT/jni/, where
$PROJECTpoints to your application's
project directory. Another alternative(二中择一;供替代的选择) is to place it under a sub-directory of the top-level
$NDK/apps/directory. For example:
$NDK/apps/<myapp>/Application.mk
Here,
<myapp>is a short name used to describe your app to the NDK build system. It doesn't actually go into your generated shared libraries or your final packages.
Variables变量函数
APP_PROJECT_PATH
This variable stores the absolute path to your app's project-root directory. The build system uses this information to place stripped-down定制 versions of the generated JNI shared libraries into a specific locationknown to the APK-generating tools.
If you place放置 your
Application.mkfile under
$NDK/apps/<myapp>/, you must define this variable. If you place it under
$PROJECT/jni/,
it is optional.
APP_OPTIM
Define this optional variable as eitherreleaseor
debug. You use it to alter改动 the optimization最佳化,最优化 level when building your application's modules.
Release mode is the default, and generates highly optimized binaries. Debug mode generates unoptimized binaries that are much easier to debug.
Note that you can debug either release or debug binaries. Release binaries, however, provide less information during debugging. For example, the build system optimizes out优化了 some variables, preventing you from
inspecting检查 them. Also, code re-ordering重组 can make it more difficult to step through the code; stack traces堆栈跟踪 may not be reliable可靠.
Declaring
android:debuggablein your application manifest's
<application>tag will cause this variable to default to
debuginstead of
release.
Override this default value by setting
APP_OPTIMto
release.
APP_CFLAGS
This variable stores a set of C compiler flags that the build system passes to the compiler when compiling any C or C++ source code for any of the modules. You can use this variable to change the build of a givenmodule according根据 to the application that needs it, instead of having to modify the
Android.mkfile itself.
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.mkthat you want to add the path to the
barsources during compilation, you should use:
APP_CFLAGS += -Isources/bar
Or, alternatively:
APP_CFLAGS += -I$(LOCAL_PATH)/../bar
-I../barwill not work since it is equivalent等价 to
-I$NDK_ROOT/../bar.
Note: This variable only works on C, not C++, sources in android-ndk-1.5_r1. In all versions after that one,
APP_CFLAGSmatches the full Android build system.
APP_CPPFLAGS
This variable contains a set of C++ compiler flags that the build system passes to the compiler when building only C++ sources.Note: In android-ndk-1.5_r1, this variable works on both C and C++ sources. In all subsequent(随后的后来的后面的
) versions of the NDK,
APP_CPPFLAGSnow matches the full Android build system. For flags that apply to both C and C++ sources,
use
APP_CFLAGS.
APP_LDFLAGS
A set of linker flags that the build system passes when linking the application. This variable is only relevant相关的 when the build system is building shared libraries and executables. When the build system buildsstatic libraries, it ignores these flags.
APP_BUILD_SCRIPT
By default, the NDK build system looks underjni/for a file named
Android.mk.
If you want to override this behavior, you can define
APP_BUILD_SCRIPTto point to an alternate build script. The build system always interprets解释 a non-absolute
path as relative to the NDK's top-level directory.
APP_ABI
By default, the NDK build system generates machine code for thearmeabiABI.
This machine code corresponds to an ARMv5TE-based CPU with software floating point operations. You can use
APP_ABIto select a different ABI. Table 1 shows the
APP_ABIsettings for different instruction sets.
Table 1.
APP_ABIsettings for different instruction sets.
Instruction set | Value |
---|---|
Hardware FPU instructions on ARMv7 based devices | APP_ABI := armeabi-v7a |
ARMv8 AArch64 | APP_ABI := arm64-v8a |
IA-32 | APP_ABI := x86 |
Intel64 | APP_ABI := x86_64 |
MIPS32 | APP_ABI := mips |
MIPS64 (r6) | APP_ABI := mips64 |
All supported instruction sets | APP_ABI := all |
allis available starting from NDKr7.
You can also specify multiple values by placing them on the same line, delimited by spaces. For example:
APP_ABI := armeabi armeabi-v7a x86 mips
For the list of all supported ABIs and details about their usage and limitations, refer to ABI
Management.
APP_PLATFORM
This variable contains the name of the target Android platform. For example,android-3specifies the Android 1.5 system images. For a complete list of platform names and corresponding Android
system images, seeAndroid NDK Native 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. In addition, it comes with alternative C++
implementations that you can use or link to in your own applications. Use
APP_STLto select one of them. For information about the supported runtimes, and the features they offer, see NDK
Runtimes and Features.
APP_SHORT_COMMANDS
The equivalent相等的 ofLOCAL_SHORT_COMMANDSin
Application.mkfor your whole project. For more information, see the documentation for this
variable on
Android.mk.
NDK_TOOLCHAIN_VERSION
Define this variable as either4.9or
4.8to select a version of the GCC compiler.Version 4.9 is the default for
64-bit ABIs, and 4.8 is the default for 32-bit ABIs. To select a version of Clang, define this variable as
clang3.4,
clang3.5, or
clang. Specifying
clangchooses
the most recent version of Clang.
APP_PIE
Starting from Android 4.1 (API level 16), Android's dynamic动态 linker supports position-independent executables (PIE). From Android 5.0 (API level 21), executables require PIE. To use PIE to build your executables,set the
-fPIEflag. This flag makes it harder to exploit开发利用 memory corruption(贪污腐败
堕落) bugs by randomizing(随机化) code location. By default,
ndk-buildautomatically sets this value to
trueif your project
targets
android-16or higher. You may set it manually手动 to either
trueor
false.
This flag applies only to executables. It has no effect when building shared or static libraries.
Note: PIE executables cannot run on Android releases prior to 4.1.
This restriction约束 only applies to executables. It has no effect when building shared or static libraries.
APP_THIN_ARCHIVE
Sets the default value ofLOCAL_THIN_ARCHIVEin the
Android.mkfile for all static library modules in this project. For more information, see the documentation for
LOCAL_THIN_ARCHIVEon
Android.mk.
相关文章推荐
- Android NDK开发之:配置环境的详解
- Android开发的IDE、ADT、SDK、JDK、NDK等名词解释
- Android提高之使用NDK把彩图转换灰度图的方法
- 探讨:如何在NDK中呼叫Java的class
- Android App 增量更新实例(Smart App Updates)
- 每周总结20130814——Android NDK环境的搭建和使用,YUV420SP格式图像的处理
- Android NDK开发简介
- Android NDK开发之Jni的数据类型
- Android NDK开发之数组类型的操作
- Android NDK开发之Jni调用Java对象
- Getting Started With the NDK(Pro Android Apps Performance Optimization)
- Advanced NDK(Pro Android Apps Performance Optimization)
- Android新版NDK环境配置(免Cygwin)
- android ndk 怎样调用第三方的so库文件
- Android 开发 ndk相关问题
- Android: NDK编程入门笔记
- windows下eclipse搭建android_ndk开发环境
- 基于NDK的Android防破解
- Android ndk开发之在c文件里打印log
- Android NDK 之 NDK 预生库支持