ndk-build
2015-10-14 23:05
393 查看
ndk-build
On this page
InternalsInvoking from the Command Line
Invoking from Eclipse
64-Bit and 32-Bit Toolchains
Requirements
The
ndk-buildfile is a shell script introduced in Android NDK r4. Its purpose is to invoke the right NDK build script.
Internals
Running the ndk-buildscript is equivalent to running the following command:
$GNUMAKE -f <ndk>/build/core/build-local.mk <parameters>
$GNUMAKEpoints to GNU Make 3.81 or later, and
<ndk>points to your NDK installation directory. You can use this information to invoke ndk-build from other shell scripts,
or even your own make files.
Invoking from the Command Line
The ndk-buildfile lives in the top level the NDK installation directory. To run it from the command line, invoke it while in or under your application project directory. For example:
cd <project> $ <ndk>/ndk-build
In this example,
<project>points to your project’s root directory, and
<ndk>is the directory where you installed the NDK.
Options
All parameters to ndk-build are passed directly to the underlying GNUmakecommand that runs the NDK build scripts. Combine
ndk-buildand options in the form
ndk-build <option>. For example:
$ ndk-build clean
The following options are available:
cleanRemove any previously generated binaries.
V=1Launch build, and display build commands.
-BForce a complete rebuild.
-B V=1Force a complete rebuild, and display build commands.
NDK_LOG=1Display internal NDK log messages (used for debugging the NDK itself).
NDK_DEBUG=1Force a debuggable build (see Table 1).
NDK_DEBUG=0Force a release build (see Table 1).
NDK_HOST_32BIT=1Always use the toolchain in 32-bit mode (see 64-bit and 32-bit Toolchains).
NDK_APPLICATION_MK=<file>Build, using a specific
Application.mkfile pointed to by the
NDK_APPLICATION_MKvariable.
-C <project>Build the native code for the project path located at
<project>. Useful if you don't want to
cdto it in your terminal.
Invoking from Eclipse
To build from Eclipse, make sure that you have configured it as described in Setup.If you wish to build using the default
ndk-buildcommand, with no options, you can just build your project just as you would any Android project. To get Eclipse to add any of the options described above, follow these steps:
In the Project Explorer pane, right-click your project name.
Select Properties.
Click C/C++ Build.
Under the Builder Settings tab, uncheck Use default build command.
In the Build command field, enter the entire build string as if you were typing it on the command line.
Click OK.
Figure 1 shows an example of an entered string.
![](http://developer.android.com/ndk/guides/images/NDK_build_string.png)
Figure 1. Specifying a debug build from within Eclipse
Debuggable versus Release builds
Use theNDK_DEBUGoption and, in certain cases,
AndroidManifest.xmlto specify debug or release build, optimization-related behavior, and inclusion of symbols. Table 1
shows the results of each possible combination of settings.
Table 1. Results of
NDK_DEBUG(command line) and
android:debuggable(manifest) combinations.
NDK_DEBUG=0 | NDK_DEBUG=1 | NDK_DEBUG not specified | |
---|---|---|---|
android:debuggble="true" | Debug; Symbols; Optimized*1 | Debug; Symbols; Not optimized*2 | (same as NDK_DEBUG=1) |
android:debuggable="false" | Release; Symbols; Optimized | Release; Symbols; Not optimized | Release; No symbols; O d843 ptimized*3 |
*2: Default for running
ndk-gdb.
*3: Default mode.
Note:
NDK_DEBUG=0is the equivalent of
APP_OPTIM=release, and complies with the GCC
-O2option.
NDK_DEBUG=1is the equivalent of
APP_OPTIM=debugin
Application.mk,
and complies with the GCC
-O0option. For more information about
APP_OPTIM, see Application.mk.
The syntax on the command line is, for example:
$ ndk-build NDK_DEBUG=1
If you are using build tools from prior to SDK r8, you must also modify your
AndroidManifest.xmlfile to specify debug mode. The syntax for doing so resembles the following:
<application android:label="@string/app_name" android:debuggable="true">
From SDK r8 onward, you do not need to touch
AndroidManifest.xml. Building a debug package (e.g. with ant debug or the corresponding option of the ADT plugin) causes the tool automatically to pick the native debug files generated with
NDK_DEBUG=1.
64-Bit and 32-Bit Toolchains
Some toolchains come with both 64-bit and 32-bit versions. For example, directories<ndk>/toolchain/<name>/prebuilt/and
<ndk>/prebuilt/may contain both
linux-x86and
linux-x86_64folders
for Linux tools in 32-bit and 64-bit modes, respectively. The ndk-build script automatically chooses a 64-bit version of the toolchain if the host OS supports it. You can force the use of a 32-bit toolchain by using
NDK_HOST_32BIT=1either
in your environment or on the ndk-build command line.
Note that 64-bit tools utilize host resources better (for instance, they are faster, and handle larger programs), and they can still generate 32-bit binaries for Android.
Requirements
You need GNU Make 3.81 or later to use ndk-build or the NDK in general. The build scripts will detect a non-compliant Make tool, and generate an error message.If you have GNU Make 3.81 installed, but the default
makecommand doesn’t launch it, define
GNUMAKEin your environment to point to it before launching ndk-build. For
example:
$ export GNUMAKE=/usr/local/bin/gmake $ ndk-build
You can override other host prebuilt tools in
$NDK/prebuilt/<OS>/bin/with the following environment variables:
$ export NDK_HOST_AWK=<path-to-awk> $ export NDK_HOST_ECHO=<path-to-echo> $ export NDK_HOST_CMP=<path-to-cmp>
相关文章推荐
- Model Builder空间选址建模技术
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 4 : Query Trace 2
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 4 : Query Trace 1
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 4 : Query Data IN HDFS
- UIVisualEffectView实现“弹出”提示
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 3 : hadoop-sync install
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 2 : CitusDB file_fdw usage
- CitusDB, PostgreSQLs Use Hadoop Distribute Query - 1 : Single HOST CitusDB Cluster install
- Vuejs demo
- PostgreSQL range gist index 20x+ speedup than Mysql index combine query
- 解决配置IaaS中Endpoint系统日志报错:ignoring exception:Error executin gquery usp
- duilib库分析: 消息流程分析
- Invalid result location value/parameter 解决办法
- PostgreSQL json jsonb 支持的value数据类型,如何构造一个jsonb
- I have updated Android SDK to rev. 22 yesterday and there is no apkbuilder in tools
- HDU 1711 Number Sequence(kmp)
- don't mistake the float/double's display & real value.
- 62 Unique Paths
- GUI显示系统之SurfaceFlinger
- PostgreSQL can continue when postmaster killed