Html程序  |  143行  |  5.24 KB

<html><body><pre>'ndk-build' Overview

I. Usage:
---------

The Android NDK r4 introduced a new tiny shell script, named 'ndk-build',
to simplify building machine code.

The script is located at the top-level directory of the NDK, and shall
be invoked from the command-line when in your application project
directory, or any of its sub-directories. For example:

    cd $PROJECT
    $NDK/ndk-build

Where $NDK points to your NDK installation path. You can also create an
alias or add $NDK to your PATH to avoid typing it every time.


II. Options:
------------

All parameters to 'ndk-build' are passed directly to the underlying GNU Make
command that runs the NDK build scripts. Notable uses include:

  ndk-build                  --&gt; rebuild required machine code.
  ndk-build clean            --&gt; clean all generated binaries.

  ndk-build NDK_DEBUG=1      --&gt; generate debuggable native code.

  ndk-build V=1              --&gt; launch build, displaying build commands.

  ndk-build -B               --&gt; force a complete rebuild.

  ndk-build -B V=1           --&gt; force a complete rebuild and display build
                                 commands.

  ndk-build NDK_LOG=1        --&gt; display internal NDK log messages
                                 (used for debugging the NDK itself).

  ndk-build NDK_DEBUG=1      --&gt; force a debuggable build (see below)
  ndk-build NDK_DEBUG=0      --&gt; force a release build (see below)

  ndk-build NDK_HOST_32BIT=1 --&gt; Always use toolchain in 32-bit (see below)

  ndk-build NDK_APPLICATION_MK=&lt;file&gt;
    --&gt; rebuild, using a specific Application.mk pointed to by
        the NDK_APPLICATION_MK command-line variable.

  ndk-build -C &lt;project&gt;     --&gt; build the native code for the project
                                 path located at &lt;project&gt;. Useful if you
                                 don't want to 'cd' to it in your terminal.


III. Debuggable versus Release builds:
--------------------------------------

In NDK r5, ndk-build has been modified to make it easier to switch between
release and debug builds. This is done by using the NDK_DEBUG variable.
For example:

  $NDK/ndk-build NDK_DEBUG=1  =&gt; forces the generation of debug binaries
  $NDK/ndk-build NDK_DEBUG=0  =&gt; forces the generation of release binaries

If you don't specify NDK_DEBUG, ndk-build will keep its default behaviour,
which is to inspect the AndroidManifest.xml, if any, and see if its
&lt;application&gt; element has android:debuggable="true".

IMPORTANT: If you use the build tools of SDK r8 (or higher), you
           won't need to touch your AndroidManifest.xml file at all!

           That's because if you build a debug package (e.g. with
           "ant debug" or the corresponding option of the ADT plugin),
           the tool will  automatically pick the native debug files
           generated with NDK_DEBUG=1.

Also, as a convenience, the release and debug object files generated by the
NDK are now stored in different directories (e.g. obj/local/&lt;abi&gt;/objs and
obj/local/&lt;abi&gt;/objs-debug). This avoids having to recompile all your sources
when you switch between these two modes (even when you only modified one or
two source files).


IV. 64-bit and 32-bit toolchains:
---------------------------------

Some toolchains come with both 64-bit and 32-bit versions.  For example,
directories $NDK/toolchain/&lt;name&gt;/prebuilt and $NDK/prebuilt may contains both
"linux-x86" and "linux-x86_64" folders 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=1 either in your envorinment or on the ndk-build command-line.

Note that 64-bit tools utilize host resources better (faster, handle larger
programs, etc) and they should function identically to their 32-bit counterparts.
Ie. 64-bit toolchains still generate 32-bit binaries for Android.


V. Requirements:
----------------

You need GNU Make 3.81 or later to use 'ndk-build' or the NDK in general.
The build scripts will detect that you're using a non-compliant Make tool
and will complain with an error message.

If you have GNU Make 3.81 installed, but that it is not launched by the
default 'make' command, define GNUMAKE in your environment to point to it
before launching 'ndk-build'. For example:

    GNUMAKE=/usr/local/bin/gmake ndk-build

Or to make the change more permanent:

    export GNUMAKE=/usr/local/bin/gmake
    ndk-build

Adapt to your shell and GNU Make 3.81 installation location.

You may override other host prebuilt tools in $NDK/prebuilt/&lt;OS&gt;/bin
with the following environment variables

    NDK_HOST_AWK=&lt;path-to-awk&gt;

    NDK_HOST_ECHO=&lt;path-to-echo&gt;

    NDK_HOST_CMP=&lt;path-to-cmp&gt;


VI. Internals:
--------------

'ndk-build' itself is a tiny wrapper around GNU Make, its purpose is simply
to invoke the right NDK build script, it is equivalent to;

    $GNUMAKE -f $NDK/build/core/build-local.mk [parameters]

Where '$GNUMAKE' points to GNU Make 3.81 or later, and $NDK points to your
NDK installation directory.

Use this knowledge if you want to invoke the NDK build script from other
shell scripts (or even your own Makefiles).
</pre></body></html>